generating xml

[email protected] (jux) Thu, 08 Jul 2004 16:36:58 +0300
Newsgroups php.xml.dev
Message-ID <[email protected]>
Hi

I've managed to inclue elements with php to xml file, but all the things 
  i add come in one line. Like so:
<one nr="4"><name>Patrik</name><sex>M</sex></one><one 
nr="5"><name>Patrik</name><sex>M</sex></one>

Is there a way to add "\n" (new line) characters or something to my 
script so that it is better for humans to find possible bugs or something...

Here is my script:

////////////////////////////////////////////////

<?php
  class Test{

       function Test(){
       	$name="Patrik";
         $sex="M";
       	$xmlfile=$_SERVER["DOCUMENT_ROOT"]."/xml/test.xml";
         $xmlstr=join('', file($xmlfile));
         if (!$dom= domxml_open_mem($xmlstr)){
         	die ('couldn\'t open the file.' );
         }
         $ones=$dom->get_elements_by_tagname("one");
         $last_one=$ones[count($ones)-1];
         $last_nr=$last_one->get_attribute("nr");
         // here i found the attr nr of last one, so new ones nr=last_nr++

         $root = $dom->document_element();
         $new_one=$dom->create_element("one");
         $new_one->set_attribute("nr", $last_nr+1);
         $new_name=$dom->create_element("name");
         $new_sex=$dom->create_element("sex");
         $new_name->set_content($name);
         $new_sex->set_content($sex);
         $new_one->append_child($new_name);
         $new_one->append_child($new_sex);
         $root->append_child($new_one);

         $dom->dump_file($_SERVER["DOCUMENT_ROOT"]."/xml/test.xml" 
,false ,true);
         $xmlstr = $dom->dump_mem();
         echo "<pre>";
         echo htmlentities($xmlstr);
         echo "<pre>";

       }
  }

  $test=new Test();

?>

////////////////////////////////////////