XmlWriterSettings.OmitXmlDeclaration Property
Gets or sets a value indicating whether to omit an XML declaration.
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Property Value
Type: System.Booleantrue to omit the XML declaration; otherwise, false. The default is false, an XML declaration is written.
This property only applies to XmlWriter instances that output text content; otherwise, this setting is ignored.
If OmitXmlDeclaration is set to false, The XML declaration is written automatically
The XML declaration is always written if ConformanceLevel is set to Document, even if OmitXmlDeclaration is set to true.
The XML declaration is never written if ConformanceLevel is set to Fragment. You can call WriteProcessingInstruction to explicitly write out an XML declaration.
The following example writes an XML fragment to a memory stream.
XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.ConformanceLevel = ConformanceLevel.Fragment; settings.CloseOutput = false; // Create the XmlWriter object and write some content. MemoryStream strm = new MemoryStream(); XmlWriter writer = XmlWriter.Create(strm, settings); writer.WriteElementString("orderID", "1-456-ab"); writer.WriteElementString("orderID", "2-36-00a"); writer.Flush(); writer.Close(); // Do additonal processing on the stream.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.