I have an XML file created using XDocument from System.Xml.Linq
<?xml version="1.0" encoding="utf-8"?><MyCommands version="014"><Commands><Global><Command name="command 46><description></description><content type="Basic"><![CDATA[Sub Main SendKeys"test" End Sub ]]></content></Command></Global></Commands></MyCommands>
I then use the code below to read the XML file and write the CData to a text file using my StreamWriter (myTextFileWriter) but the CDATA above would appear in my text file as:
Sub MainSendKeys "test"End Sub
How do I preserve the line breaks and write them to the file?
Many thanks
public void writeXMLContent() { XDocument doc = XDocument.Load(commandsFilePath, LoadOptions.PreserveWhitespace); foreach (var item in doc.Descendants("Command")) { myTextFileWriter.Write(item.Element("content").Value); } }