Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Keeping line breaks when writing to a file

$
0
0

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);
}                       
}





Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>