Jump to content

XML formatting


optikalefx

Recommended Posts

so i have a simple xml document.

<?xml version="1.0" standalone="yes"?>
<newsletter>
<num>5</num>
	<person>
		<fname>
		Sean
		</fname>
		<lname>
		Clark
		</lname>
		<email>
		sean@4tenonline.com
		</email>
	</person>
	<person>
		<fname>
		Dan
		</fname>
		<lname>
		Schepleng
		</lname>
		<email>
		dan@4tenonline.com
		</email>
	</person>

<person><fname>paul</fname><lname>boudra</lname><email>paul@4tenonline.com</email></person><person><fname>michele</fname><lname>blaustein</lname><email>freenow529@aol.com</email></person><person><fname>Steve</fname><lname>Jobs</lname><email>Steve@mac.com</email></person></newsletter>

 

as you can see, when i add nodes using code, it just puts them on a single line.  Is there any way to keep it formatted?  The first few that are actually formatted were manually put in, the rest was generated with php code.

Link to comment
Share on other sites

this generates the data so i can read it

<?php
echo "<table cellspacing=8";
$xml = simplexml_load_file('people.xml');
$num=$xml->num;
for ($i = 0 ; $i < $num; $i++) {
$var=$xml->person[$i];
echo "<tr>";
echo "<td>" . $var->fname . " " . $var->lname . "</td><td>" . $var->email . "</td></tr>";
}

echo "</table><br><br><br>Copy this list for emailage<br>";
for ($i = 0 ; $i < $num; $i++) {
$var=$xml->person[$i];
echo $var->email .", ";
}

?>

 

and this inputs the data from an html form

<?php

//Get values from form store in PHP variables
$fname = $_REQUEST["fname"];
$lname = $_REQUEST["lname"];
$email = $_REQUEST["email"];

//Load XML document
$xml = simplexml_load_file('newsletter/people.xml');

//Get number of contacts, add one to it
$xml->num[0]+=1;

//Add node link, and First name
$input = $xml->addChild('person');
$input->addChild('fname',$fname);
$input->addChild('lname',$lname);
$input->addChild('email',$email);

//Save and output the xml file
$xml->asXML("newsletter/people.xml");

?>

 

Link to comment
Share on other sites

I have never worked with anything like what you are doing,

but I can tell you this what you need to input, I just dont

know where to input it.

 

insert "\n"

when you want a line break and as far as the spacing

you can just have a variable with the spacing and insert

that before text, example:

<?php
$level_1 = '            ';
$level_2 = '                ';
// echo $level_1 and then insert the text and then put \n;
// echo $level_2 and then insert the text and then put \n;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.