Connecting Tech Pros Worldwide Forums | Help | Site Map

domDocument and XML

Andrew M.
Guest
 
Posts: n/a
#1: Jul 17 '05
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.

example:

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

instead of

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

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.

Felix
Guest
 
Posts: n/a
#2: Jul 17 '05

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
library.

Hope this helps,
Felix

Closed Thread