XmlWriter.Create Method (String)

 

Creates a new XmlWriter instance using the specified filename.

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

public static XmlWriter Create(
	string outputFileName
)

Parameters

outputFileName
Type: System.String

The file to which you want to write. The XmlWriter creates a file at the specified path and writes to it in XML 1.0 text syntax. The outputFileName must be a file system path.

Return Value

Type: System.Xml.XmlWriter

An XmlWriter object.

Exception Condition
ArgumentNullException

The url value is null.

When you use this overload, an XmlWriterSettings object with default settings is used to create the XML writer.

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

If you want to specify the features to support on the created XML writer, use an overload that takes an XmlWriterSettings object as one of its arguments, and pass in a XmlWriterSettings object with your custom settings.

The following example creates an XmlWriter object and writes a book node.

using (XmlWriter writer = XmlWriter.Create("output.xml"))
{
    writer.WriteStartElement("book");
    writer.WriteElementString("price", "19.95");
    writer.WriteEndElement();
    writer.Flush();
}

.NET Framework
Available since 2.0
Return to top
Show: