I am using a DOMDocument
to add new nodes to an XML file using PHP. I am using the createElement()
and appendChild()
functions.
The problem is that the indentation of the tags in the XML is lost. How can I keep the indentation in the XML or re-indent after addition of a node?
My XML before modification is nicely indented:
<my_xml>
<level>Some level</level>
</my_xml>
But after modification, the indentation is lost:
<my_xml>
<level>Some level</level>
<level>New Level</level></my_xml>