Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

XmlWriter.Create Method (String, XmlWriterSettings)


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

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

public static XmlWriter Create(
	string outputFileName,
	XmlWriterSettings settings


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.

Type: System.Xml.XmlWriterSettings

The XmlWriterSettings object used to configure the new XmlWriter instance. If this is null, a XmlWriterSettings with default settings is used.

If the XmlWriter is being used with the Transform method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. This ensures that the created XmlWriter object has the correct output settings.

Return Value

Type: System.Xml.XmlWriter

An XmlWriter object.

Exception Condition

The url value is null.

The following example creates an XmlWriter object with the defined settings.

using System;
using System.IO;
using System.Xml;
using System.Text;

public class Sample {

  public static void Main() {

    XmlWriter writer = null;

    try {

       // Create an XmlWriterSettings object with the correct options. 
       XmlWriterSettings settings = new XmlWriterSettings();
       settings.Indent = true;
       settings.IndentChars = ("\t");
       settings.OmitXmlDeclaration = true;

       // Create the XmlWriter object and write some content.
       writer = XmlWriter.Create("data.xml", settings);
       writer.WriteElementString("item", "tesing");


     finally  {
        if (writer != null)

.NET Framework
Available since 2.0
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft