Last active
December 9, 2025 15:24
-
-
Save Microsofttechies/d5eb04e6201f2177eff2 to your computer and use it in GitHub Desktop.
How to prevent XDocument from adding XML version and encoding information C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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