I need to save one XmlDocument
to file with proper indentation (Formatting.Indented)
but some nodes with their children have to be in one line (Formatting.None)
.
How to achieve that since XmlTextWriter
accept setting for a whole document?
Edit after @Ahmad Mageed's resposne:
I didn't know that XmlTextWriter settings can be modified during writing. That's good news.
Right now I'm saving xmlDocument (which is already filled with nodes, to be specific it is .xaml page) this way:
XmlTextWriter writer = new XmlTextWriter(filePath, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
xmlDocument.WriteTo(writer);
writer.Flush();
writer.Close();
It enables indentation in all nodes, of course. I need to disable indentation when dealing with all <Run>
nodes.
In your example you write to XmlTextWriter "manually".
Is there an easy way to crawl through all xmlDocument nodes and write them to XmlTextWriter so I can detect <Run>
nodes? Or do I have to write some kind of recursive method that will go to every child of current node?