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 Shared Function Create (
	outputFileName As String,
	settings As XmlWriterSettings
) As XmlWriter


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.

Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports Microsoft.VisualBasic

Public Class Sample 

  Public Shared Sub Main() 

    Dim writer As XmlWriter = Nothing


       ' Create an XmlWriterSettings object with the correct options. 
       Dim settings As XmlWriterSettings = New XmlWriterSettings()
       settings.Indent = true
       settings.IndentChars = (ControlChars.Tab)
       settings.OmitXmlDeclaration = true

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


         If Not (writer Is Nothing) Then
         End If
      End Try

   End Sub 
End Class 

.NET Framework
Available since 2.0
Return to top