domDocument and XML

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am using a php5 script to insert data into an xml file. The problem I
am having is that when I insert a new child node, it is inserted on the
same line as the node it is supposed to be inserted before. It all works
  but makes for a sloppy XML file after inserting new child nodes.


<song artist="blah"/><song artist="blah2"/>

instead of

<song artist="blah"/>
<song artist="blah2"/>

This is how I would like it. How do I get it to \r\n after inserting the
new child?

Thanks in advance for any help.

Re: domDocument and XML

What you need is to tidy up your XML *after* generating it.
Look up Function Reference -> Tidy Functions in the PHP5
manual. It's a binding for HTML Tidy, but it might just
work for XML, or maybe you can find a similar, XML-specific

Hope this helps,

Site Timeline