I'm going to cheat a little here, but I will say that with the "indent wrong" you mean that it has no indentation at all.
libxml2 by default will not backslide from your XML file, because in XML spaces (including those used for indentation) are significant data. That is, this XML file:
<root> <foo>Bar</foo> </root>
semantically different from:
<root><foo>Bar</foo></root>
... is that two character parts of the data from the first XML file may be important to you, the programmer, so the XML leaves them there when it reads the file, and will not output them (if not specified) when writing.
However, this is too common an XML bit. Most of the XML I've seen is sadly indented. Libxml2 has options for automatically indenting when writing and deleting it when reading, but note: there are some caveats: this may be wrong. Documents say more.
I think this function can help you (I never used it myself :-)) if you want it to be indented for you: xmlTextWriterSetIndent
Listen to the warning here: libxml2 FAQ
And the information here: XML Specification
Thanatos
source share