Thursday, 19 March 2015

How to prevent XDocument from adding XML version and encoding information C#


XmlDocument xdoc = new XmlDocument();
TextWriter wwriter = new StreamWriter("c:/a.xml");
//Do your logic to add all tags to xdoc
////with Tag <?xml version="1.0" encoding="utf-8"?>
//xdoc.Save(wwriter);
////without tag- <?xml version="1.0" encoding="utf-8"?>
XmlWriterSettings xws = new XmlWriterSettings { OmitXmlDeclaration = true };
using (XmlWriter xw = XmlWriter.Create(wwriter, xws))
xdoc.Save(xw);
view raw gistfile1.cs hosted with ❤ by GitHub