c# - Save xml string or XmlNode to text file in indent format? -


I have an XML string that is too long in a line. I would like to save the XML string in a beautiful indent format:

  & lt; Root & gt; & Lt; App & gt; MyApp & lt; / App & gt; & Lt; LogFile & gt; MyApp.log & lt; / Logfile & gt; & Lt; SQLdb & gt; & Lt; Connection & gt; ... & lt; / Connection & gt; ... & lt; / Root & gt;  

I like the format:

  & lt; Root & gt; & Lt; Applications & gt; MyApp & lt; / Apps & gt; & Lt; Logfile & gt; MyApp.log & lt; / Logfile & gt; & Lt; SQLdb & gt; & Lt; Connection & gt; ... & lt; / Connection & gt; .... & lt; / SQLdb & gt; & Lt; / Root & gt;  

What are the Net Libraries available for C #?

This will work for what you want to do ...

 < Code> var samp = @ "& lt; root & gt; & lt; ap & gt; myApp & lt; / app & gt; & lt; logFile & gt; myApp.log & lt; / logfile & gt; & lt; ; / Root> "; Var xdoc = XDocument.Load (new string reader (damp), loadopts.Non); Xdoc.Save (@ "c: \ temp \ myxml.xml", SaveOptions.None);  

The same result with the System.Xml namespace ...

  var xdoc = New XmlDocument (); Xdoc.LoadXml (samp); Xdoc.Save (@ "c: \ Temporary \ myxml.xml");  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -