how to create an xml using xml writer without declaration element

ninithepug picture ninithepug · Jul 26, 2011 · Viewed 19.9k times · Source

I am using XmlWriter.Create() to get a writer instance then write the XML, but the result has the <?xml version="1.0" encoding="utf-16" ?>, how do I tell my xml writer do not produce it?

Answer

Kirill Polishchuk picture Kirill Polishchuk · Jul 26, 2011

Use XmlWriterSettings.OmitXmlDeclaration.

Don't forget to set XmlWriterSettings.ConformanceLevel to ConformanceLevel.Fragment.