I know that pretty print questions have been asked countless times, but i haven't found any information to solve my problem.
I am writing a tool to strip xml files of their contents and later insert new content to the skeleton that was left.
Basically the xml looks like this beforehand:
<file>
Some text which is not in a tag (not my decision)
<index>Index 1</index>
<entry att1='val1' att2='val2'>
<text>some text</text>
<relations>some information</relations>
</entry>
</file>
additional to the text and relations subelements there are other subelements. What i do is to delete all sub elements of all entry elements beside the relations element. Afterwards the file gets saved and this is where the fun starts.
I use the XmlDocument
class , set the PreserveWhitespace
Property to true to have all the texts keep their whitespaces and linebreaks. I save the file by using a XmlWriter
created with XmlWriterSettings
set to intend and to replace all linebreaks with the `Environment.NewLine.
The file ends up having all kind of entry elements in one line until a new index element starts, which has some text in it. Which is really strange, since there is text in the relations elements as well.
Using the XDoc
class to try to pretty-print the output didn't work as well. I just want all elements on a new line each.