Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create an xml using xml writer without declaration element

Tags:

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?

like image 543
ninithepug Avatar asked Jul 26 '11 16:07

ninithepug


People also ask

Is XML declaration necessary?

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.

Is XML optional declaration?

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.

How do you create an XmlWriter?

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.

What is standalone in XML declaration?

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.


1 Answers

Use XmlWriterSettings.OmitXmlDeclaration.

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

like image 119
Kirill Polishchuk Avatar answered Oct 15 '22 19:10

Kirill Polishchuk