XmlWriterSettings.OmitXmlDeclaration Property
Gets or sets a value indicating whether to write an XML declaration.
Assembly: System.Xml (in System.Xml.dll)
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 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.