Skip to content

Instantly share code, notes, and snippets.

@Microsofttechies
Last active December 9, 2025 15:24
Show Gist options
  • Select an option

  • Save Microsofttechies/d5eb04e6201f2177eff2 to your computer and use it in GitHub Desktop.

Select an option

Save Microsofttechies/d5eb04e6201f2177eff2 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment