I’m having an XML which will look like following
<root>
<node>
<a1>text</a1>
<a2>text</a2>
<a3></a3>
</node>
</root>
If i loaded this in a xmldocument and saved it. The xml becomes following
<root>
<node>
<a1>text</a1>
<a2>text</a2>
<a3>
</a3>
</node>
</root>
My code snippet:
public static Void Update(String Path)
{
FileStream docIn = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlDocument xml = new XmlDocument();
xml.Load(Path);
XmlNodeList nodeY = xml.SelectNodes("/root/node/a1");
_count = 0;
foreach (XmlNode live in nodeY)
{
//changing nodeY InnerText
}
xml.Save(Path);
}
I do not wish to use the preservewhitespace= true option since it makes my xml looks like this
<root><node><a1>text</a1><a2>text</a2><a3></a3></node></root>
Thanks in advance!!!
Try to specify
XmlWritersettings explicitly using an instanceXmlWriterSettingsclass.Hope this helps.