I have an xml file I am reading in that is formatted as such:
<?xml version="1.0" encoding="utf-8"?>
<Screen_Monitoring>
<Interval>
0.05
</Interval>
<sendCommand>
<![CDATA[01 30 41 30 41 30 36 02 30 31 44 36 03]]>
</sendCommand>
</Screen_Monitoring>
I read the xml file into an XDocument object like so:
XDocument xDoc = new XDocument();
xDoc = XDocument.Load(@"C:\MyCode\CONFIGURATION_1NS.xml");
And immediately write it back out like so:
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = " ",
NewLineChars = "\r\n",
NewLineHandling = NewLineHandling.Replace
};
using (XmlWriter writer = XmlWriter.Create(@"C:\MyCode\Config_saved.xml", settings))
{
xDoc.WriteTo(writer);
}
The output does not match the contents of the input file, as the sendCommand element has the value between the sendCommand tags on the same line as the tags, as so:
<?xml version="1.0" encoding="utf-8"?>
<Screen_Monitoring>
<Interval>
0.05
</Interval>
<sendCommand><![CDATA[01 30 41 30 41 30 36 02 30 31 44 36 03]]></sendCommand>
</Screen_Monitoring>
Unfortunately I am need to produce output xml for a program that may not work properly if the xml itself is completely valid, but it is not formatted how it wants. Is there any easy way to write out the Xml so that it will be formatted with the value on a line separate from the element tags?