.NET Framework Class Library
XmlWriter.Create Method (Stream)
Creates a new XmlWriter instance using the specified stream.
Assembly: System.Xml (in System.Xml.dll)
Syntax
Visual Basic
Public Shared Function Create ( _ output As Stream _ ) As XmlWriter
C#
public static XmlWriter Create( Stream output )
Visual C++
public: static XmlWriter^ Create( Stream^ output )
F#
static member Create : output:Stream -> XmlWriter
Parameters
- output
- Type: System.IO.Stream
The stream to which you want to write. The XmlWriter writes XML 1.0 text syntax and appends it to the specified stream.
Exceptions
| Exception | Condition |
|---|---|
| ArgumentNullException |
The stream value is null. |
Remarks
An XmlWriterSettings object with default settings is used to create the writer. If you wish to specify the features to support on the created writer, use the overload that takes an XmlWriterSettings object as one of its arguments, and pass in an XmlWriterSettings object with the correct settings.
Examples
The following example creates an XmlWriter object with the defined settings.
Visual Basic
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 Try ' 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.WriteStartElement("book") writer.WriteElementString("item", "tesing") writer.WriteEndElement() writer.Flush() Finally If Not (writer Is Nothing) Then writer.Close() End If End Try End Sub End Class
C#
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.WriteStartElement("book"); writer.WriteElementString("item", "tesing"); writer.WriteEndElement(); writer.Flush(); } finally { if (writer != null) writer.Close(); } } }
Version Information
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Portable Class Library
Supported in: Portable Class LibraryPlatforms
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.
See Also