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?
The XML declaration is mandatory if the encoding of the document is anything other than UTF-8 or UTF-16. In practice, this means that documents encoded using US-ASCII can also omit the XML declaration because US-ASCII overlaps entirely with UTF-8. Only one encoding can be used for an entire XML document.
XML declaration contains details that prepare an XML processor to parse the XML document. It is optional, but when used, it must appear in the first line of the XML document.
Creates a new XmlWriter instance using the stream and XmlWriterSettings object. Creates a new XmlWriter instance using the specified XmlWriter and XmlWriterSettings objects. Creates a new XmlWriter instance using the specified StringBuilder. Creates a new XmlWriter instance using the specified filename.
The XML standalone element defines the existence of an externally-defined DTD. In the message tree it is represented by a syntax element with field type XML. standalone. A value of no indicates that this XML document is not standalone, and depends on an externally-defined DTD.
Use XmlWriterSettings.OmitXmlDeclaration
.
Don't forget to set XmlWriterSettings.ConformanceLevel
to ConformanceLevel.Fragment
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With