optikalefx Posted December 15, 2007 Share Posted December 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 can we see your PHP script? Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 15, 2007 Author Share Posted December 15, 2007 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"); ?> Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 15, 2007 Share Posted December 15, 2007 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; ?> Quote Link to comment Share on other sites More sharing options...
optikalefx Posted December 15, 2007 Author Share Posted December 15, 2007 that would be cool...but! i can echo fine. I need it to be saved in the right format. Like the function is addChild() i cant really insert a \n there. When you go to www.ste.com/file.xml and view source, its all one line, which is annoying. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.