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>
		[email protected]
		</email>
	</person>
	<person>
		<fname>
		Dan
		</fname>
		<lname>
		Schepleng
		</lname>
		<email>
		[email protected]
		</email>
	</person>

<person><fname>paul</fname><lname>boudra</lname><email>[email protected]</email></person><person><fname>michele</fname><lname>blaustein</lname><email>[email protected]</email></person><person><fname>Steve</fname><lname>Jobs</lname><email>[email protected]</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
https://forums.phpfreaks.com/topic/81780-xml-formatting/
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
https://forums.phpfreaks.com/topic/81780-xml-formatting/#findComment-415485
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
https://forums.phpfreaks.com/topic/81780-xml-formatting/#findComment-415508
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.