XmlWriter.Create Method

 

Creates a new XmlWriter instance.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCreate(Stream)

Creates a new XmlWriter instance using the specified stream.

System_CAPS_pubmethodSystem_CAPS_staticCreate(Stream, XmlWriterSettings)

Creates a new XmlWriter instance using the stream and XmlWriterSettings object.

System_CAPS_pubmethodSystem_CAPS_staticCreate(String)

Creates a new XmlWriter instance using the specified filename.

System_CAPS_pubmethodSystem_CAPS_staticCreate(String, XmlWriterSettings)

Creates a new XmlWriter instance using the filename and XmlWriterSettings object.

System_CAPS_pubmethodSystem_CAPS_staticCreate(StringBuilder)

Creates a new XmlWriter instance using the specified StringBuilder.

System_CAPS_pubmethodSystem_CAPS_staticCreate(StringBuilder, XmlWriterSettings)

Creates a new XmlWriter instance using the StringBuilder and XmlWriterSettings objects.

System_CAPS_pubmethodSystem_CAPS_staticCreate(TextWriter)

Creates a new XmlWriter instance using the specified TextWriter.

System_CAPS_pubmethodSystem_CAPS_staticCreate(TextWriter, XmlWriterSettings)

Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.

System_CAPS_pubmethodSystem_CAPS_staticCreate(XmlWriter)

Creates a new XmlWriter instance using the specified XmlWriter object.

System_CAPS_pubmethodSystem_CAPS_staticCreate(XmlWriter, XmlWriterSettings)

Creates a new XmlWriter instance using the specified XmlWriter and XmlWriterSettings objects.

Some of the Create overloads include a settings parameter that accepts an XmlWriterSettings object. You can use this object to:

  • Specify which features you want supported on the created XmlWriter object.

  • Reuse the XmlWriterSettings object to create multiple writer objects. The XmlWriterSettings object is copied and marked read-only for each created writer. Changes to the settings on an XmlWriterSettings instance do not affect existing writers with the same settings. Thus, you can use the same settings to create multiple writers with the same functionality. Or, you can modify the settings on an XmlWriterSettings instance and create a new writer with a different set of features.

  • Add features to an existing XML writer. The Create method can accept another XmlWriter object. The underlying XmlWriter object does not have to be an XML writer created by the static Create method. For example, you can specify a user-defined XML writer to add additional features to.

  • Take full advantage of features such as better conformance checking and compliance to the XML 1.0 recommendation that are available only on XmlWriter objects created by the static Create method.

If you use a Create overload that doesn't accept an XmlWriterSettings object, the following default writer settings are used:

Setting

Default

CheckCharacters

true

CloseOutput

false

ConformanceLevel

ConformanceLevel.Document

Encoding

Encoding.UTF8

Indent

false

IndentChars

Two spaces

NamespaceHandling

Default (no removal)

NewLineChars

\r\n (carriage return, new line)

NewLineHandling

NewLineHandling.Replace

NewLineOnAttributes

false

OmitXmlDeclaration

false

OutputMethod

XmlOutputMethod.Xml

WriteEndDocumentOnClose

true

System_CAPS_noteNote

Although the .NET Framework includes the XmlTextWriter class, which is a concrete implementation of the XmlWriter class, we recommend that you create XmlWriter instances by using the Create method.

Return to top
Show: