XmlWriter.Create Método

Definición

Crea una nueva instancia de XmlWriter.Creates a new XmlWriter instance.

Sobrecargas

Create(StringBuilder, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante los objetos StringBuilder y XmlWriterSettings.Creates a new XmlWriter instance using the StringBuilder and XmlWriterSettings objects.

Create(String, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante el nombre de archivo y el objeto XmlWriterSettings.Creates a new XmlWriter instance using the filename and XmlWriterSettings object.

Create(TextWriter, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante los objetos TextWriter y XmlWriterSettings.Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.

Create(Stream, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante la secuencia y el objeto XmlWriterSettings.Creates a new XmlWriter instance using the stream and XmlWriterSettings object.

Create(XmlWriter, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante los objetos XmlWriter y XmlWriterSettings especificados.Creates a new XmlWriter instance using the specified XmlWriter and XmlWriterSettings objects.

Create(StringBuilder)

Crea una nueva instancia de XmlWriter mediante el objeto StringBuilder especificado.Creates a new XmlWriter instance using the specified StringBuilder.

Create(String)

Crea una nueva instancia de XmlWriter mediante el nombre de archivo especificado.Creates a new XmlWriter instance using the specified filename.

Create(TextWriter)

Crea una nueva instancia de XmlWriter mediante el objeto TextWriter especificado.Creates a new XmlWriter instance using the specified TextWriter.

Create(Stream)

Crea una nueva instancia de XmlWriter mediante la secuencia especificada.Creates a new XmlWriter instance using the specified stream.

Create(XmlWriter)

Crea una nueva instancia de XmlWriter mediante el objeto XmlWriter especificado.Creates a new XmlWriter instance using the specified XmlWriter object.

Comentarios

Algunas de las Create sobrecargas incluyen un settings parámetro que acepta un XmlWriterSettings objeto.Some of the Create overloads include a settings parameter that accepts an XmlWriterSettings object. Puede utilizar este objeto para:You can use this object to:

  • Especifique las características que desea que se admitan en el XmlWriter objeto creado.Specify which features you want supported on the created XmlWriter object.

  • Reutilice el XmlWriterSettings objeto para crear varios objetos de escritura.Reuse the XmlWriterSettings object to create multiple writer objects. El objeto XmlWriterSettings se copia y se marca como solo lectura para cada sistema de escritura que se crea.The XmlWriterSettings object is copied and marked read-only for each created writer. Los cambios en los valores de una instancia de XmlWriterSettings no afectan a los sistemas de escritura existentes que tienen los mismos valores.Changes to the settings on an XmlWriterSettings instance do not affect existing writers with the same settings. Por lo tanto, puede utilizar los mismos valores para crear varios sistemas de escritura con la misma funcionalidad.Thus, you can use the same settings to create multiple writers with the same functionality. O bien, puede modificar los valores de una instancia de XmlWriterSettings y crear un nuevo sistema de escritura con un conjunto de características diferente.Or, you can modify the settings on an XmlWriterSettings instance and create a new writer with a different set of features.

  • Agregar características a un escritor de XML existente.Add features to an existing XML writer. El método Create puede aceptar otro objeto XmlWriter.The Create method can accept another XmlWriter object. El objeto subyacente no XmlWriter tiene que ser un escritor XML creado por el método estático Create .The underlying XmlWriter object does not have to be an XML writer created by the static Create method. Por ejemplo, puede especificar un escritor de XML definido por el usuario al que agregar características adicionales.For example, you can specify a user-defined XML writer to add additional features to.

  • Aproveche al máximo las características, como la mejor comprobación del cumplimiento y el cumplimiento de la recomendación XML 1,0 , que solo están disponibles en XmlWriter objetos creados por el Create método estático.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.

Si utiliza una Create sobrecarga que no acepta un XmlWriterSettings objeto, se usa la siguiente configuración de escritor predeterminada:If you use a Create overload that doesn't accept an XmlWriterSettings object, the following default writer settings are used:

ParámetroSetting DefaultDefault
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Dos espaciosTwo spaces
NamespaceHandling Default (sin eliminación)Default (no removal)
NewLineChars \r\n (retorno de carro, nueva línea)\r\n (carriage return, new line)
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Nota

Aunque el .NET Framework incluye la XmlTextWriter clase, que es una implementación concreta de la XmlWriter clase, se recomienda crear instancias mediante XmlWriter el Create método.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.

Create(StringBuilder, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante los objetos StringBuilder y XmlWriterSettings.Creates a new XmlWriter instance using the StringBuilder and XmlWriterSettings objects.

public:
 static System::Xml::XmlWriter ^ Create(System::Text::StringBuilder ^ output, System::Xml::XmlWriterSettings ^ settings);
public static System.Xml.XmlWriter Create (System.Text.StringBuilder output, System.Xml.XmlWriterSettings settings);
public static System.Xml.XmlWriter Create (System.Text.StringBuilder output, System.Xml.XmlWriterSettings? settings);
static member Create : System.Text.StringBuilder * System.Xml.XmlWriterSettings -> System.Xml.XmlWriter
Public Shared Function Create (output As StringBuilder, settings As XmlWriterSettings) As XmlWriter

Parámetros

output
StringBuilder

StringBuilder en el que se va a escribir.The StringBuilder to which to write to. El contenido que escribe XmlWriter se anexa a StringBuilder.Content written by the XmlWriter is appended to the StringBuilder.

settings
XmlWriterSettings

Objeto XmlWriterSettings que se utiliza para configurar la nueva instancia de XmlWriter.The XmlWriterSettings object used to configure the new XmlWriter instance. Si es null, se utiliza un objeto XmlWriterSettings con la configuración predeterminada.If this is null, a XmlWriterSettings with default settings is used.

Si XmlWriter se está utilizando con el método Transform(String, XmlWriter), debe usar la propiedad OutputSettings para obtener un objeto XmlWriterSettings con la configuración correcta.If the XmlWriter is being used with the Transform(String, XmlWriter) method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. Con ello se garantiza que el objeto XmlWriter creado tenga la configuración de resultados correcta.This ensures that the created XmlWriter object has the correct output settings.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor builder es null.The builder value is null.

Se aplica a

Create(String, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante el nombre de archivo y el objeto XmlWriterSettings.Creates a new XmlWriter instance using the filename and XmlWriterSettings object.

public:
 static System::Xml::XmlWriter ^ Create(System::String ^ outputFileName, System::Xml::XmlWriterSettings ^ settings);
public static System.Xml.XmlWriter Create (string outputFileName, System.Xml.XmlWriterSettings? settings);
public static System.Xml.XmlWriter Create (string outputFileName, System.Xml.XmlWriterSettings settings);
static member Create : string * System.Xml.XmlWriterSettings -> System.Xml.XmlWriter
Public Shared Function Create (outputFileName As String, settings As XmlWriterSettings) As XmlWriter

Parámetros

outputFileName
String

Archivo en el que desea escribir.The file to which you want to write. XmlWriter crea un archivo en la ruta de acceso especificada y lo escribe con la sintaxis de texto de XML 1.0.The XmlWriter creates a file at the specified path and writes to it in XML 1.0 text syntax. outputFileName debe ser una ruta del sistema de archivos.The outputFileName must be a file system path.

settings
XmlWriterSettings

Objeto XmlWriterSettings que se utiliza para configurar la nueva instancia de XmlWriter.The XmlWriterSettings object used to configure the new XmlWriter instance. Si es null, se utiliza un objeto XmlWriterSettings con la configuración predeterminada.If this is null, a XmlWriterSettings with default settings is used.

Si XmlWriter se está utilizando con el método Transform(String, XmlWriter), debe usar la propiedad OutputSettings para obtener un objeto XmlWriterSettings con la configuración correcta.If the XmlWriter is being used with the Transform(String, XmlWriter) method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. Con ello se garantiza que el objeto XmlWriter creado tenga la configuración de resultados correcta.This ensures that the created XmlWriter object has the correct output settings.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor url es null.The url value is null.

Ejemplos

En el ejemplo siguiente se crea un XmlWriter objeto con los valores definidos.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.WriteStartElement("book");
       writer.WriteElementString("item", "tesing");
       writer.WriteEndElement();
    
       writer.Flush();
     }
     finally  {
        if (writer != null)
          writer.Close();
     }
  }
}
Imports System.IO
Imports System.Xml
Imports System.Text

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 

Se aplica a

Create(TextWriter, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante los objetos TextWriter y XmlWriterSettings.Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.

public:
 static System::Xml::XmlWriter ^ Create(System::IO::TextWriter ^ output, System::Xml::XmlWriterSettings ^ settings);
public static System.Xml.XmlWriter Create (System.IO.TextWriter output, System.Xml.XmlWriterSettings settings);
public static System.Xml.XmlWriter Create (System.IO.TextWriter output, System.Xml.XmlWriterSettings? settings);
static member Create : System.IO.TextWriter * System.Xml.XmlWriterSettings -> System.Xml.XmlWriter
Public Shared Function Create (output As TextWriter, settings As XmlWriterSettings) As XmlWriter

Parámetros

output
TextWriter

TextWriter en el que se desea escribir.The TextWriter to which you want to write. XmlWriter escribe la sintaxis de texto de XML 1.0 y la anexa al TextWriter especificado.The XmlWriter writes XML 1.0 text syntax and appends it to the specified TextWriter.

settings
XmlWriterSettings

Objeto XmlWriterSettings que se utiliza para configurar la nueva instancia de XmlWriter.The XmlWriterSettings object used to configure the new XmlWriter instance. Si es null, se utiliza un objeto XmlWriterSettings con la configuración predeterminada.If this is null, a XmlWriterSettings with default settings is used.

Si XmlWriter se está utilizando con el método Transform(String, XmlWriter), debe usar la propiedad OutputSettings para obtener un objeto XmlWriterSettings con la configuración correcta.If the XmlWriter is being used with the Transform(String, XmlWriter) method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. Con ello se garantiza que el objeto XmlWriter creado tenga la configuración de resultados correcta.This ensures that the created XmlWriter object has the correct output settings.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor text es null.The text value is null.

Ejemplos

En el ejemplo siguiente se escribe una cadena XML.The following example writes out an XML string.

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
StringWriter sw = new StringWriter();

using (XmlWriter writer = XmlWriter.Create(sw, settings))
{
    writer.WriteStartElement("book");
    writer.WriteElementString("price", "19.95");
    writer.WriteEndElement();
    writer.Flush();

    String output = sw.ToString();
}

Dim settings As New XmlWriterSettings()
settings.OmitXmlDeclaration = True
Dim sw As New StringWriter()
        
Using writer As XmlWriter = XmlWriter.Create(sw, settings)
  writer.WriteStartElement("book")
  writer.WriteElementString("price", "19.95")
  writer.WriteEndElement()
  writer.Flush()
            
  Dim output As String = sw.ToString()
End Using

Se aplica a

Create(Stream, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante la secuencia y el objeto XmlWriterSettings.Creates a new XmlWriter instance using the stream and XmlWriterSettings object.

public:
 static System::Xml::XmlWriter ^ Create(System::IO::Stream ^ output, System::Xml::XmlWriterSettings ^ settings);
public static System.Xml.XmlWriter Create (System.IO.Stream output, System.Xml.XmlWriterSettings settings);
public static System.Xml.XmlWriter Create (System.IO.Stream output, System.Xml.XmlWriterSettings? settings);
static member Create : System.IO.Stream * System.Xml.XmlWriterSettings -> System.Xml.XmlWriter
Public Shared Function Create (output As Stream, settings As XmlWriterSettings) As XmlWriter

Parámetros

output
Stream

Flujo en el que desea escribir.The stream to which you want to write. XmlWriter escribe la sintaxis de texto de XML 1.0 y la anexa a la secuencia especificada.The XmlWriter writes XML 1.0 text syntax and appends it to the specified stream.

settings
XmlWriterSettings

Objeto XmlWriterSettings que se utiliza para configurar la nueva instancia de XmlWriter.The XmlWriterSettings object used to configure the new XmlWriter instance. Si es null, se utiliza un objeto XmlWriterSettings con la configuración predeterminada.If this is null, a XmlWriterSettings with default settings is used.

Si XmlWriter se está utilizando con el método Transform(String, XmlWriter), debe usar la propiedad OutputSettings para obtener un objeto XmlWriterSettings con la configuración correcta.If the XmlWriter is being used with the Transform(String, XmlWriter) method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. Con ello se garantiza que el objeto XmlWriter creado tenga la configuración de resultados correcta.This ensures that the created XmlWriter object has the correct output settings.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor stream es null.The stream value is null.

Ejemplos

En el ejemplo siguiente se escribe un fragmento XML en una secuencia de memoria.The following example writes an XML fragment to a memory stream.

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;

// Create the XmlWriter object and write some content.
MemoryStream strm = new MemoryStream();
XmlWriter writer = XmlWriter.Create(strm, settings);
writer.WriteElementString("orderID", "1-456-ab");
writer.WriteElementString("orderID", "2-36-00a");
writer.Flush();
writer.Close();

// Do additional processing on the stream.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.OmitXmlDeclaration = true
settings.ConformanceLevel = ConformanceLevel.Fragment
settings.CloseOutput = false

' Create the XmlWriter object and write some content.
Dim strm as MemoryStream = new MemoryStream()
Dim writer As XmlWriter = XmlWriter.Create(strm, settings)
writer.WriteElementString("orderID", "1-456-ab")
writer.WriteElementString("orderID", "2-36-00a")
writer.Flush()
writer.Close()

' Do additional processing on the stream.

Comentarios

XmlWriter siempre escribe una marca de orden de bytes (BOM) en el flujo de datos subyacente; sin embargo, algunas secuencias no deben tener una BOM.XmlWriter always writes a Byte Order Mark (BOM) to the underlying data stream; however, some streams must not have a BOM. Para omitir la marca BOM, cree un nuevo XmlWriterSettings objeto y establezca la propiedad Encoding en un nuevo UTF8Encoding objeto con el valor booleano en el constructor establecido en false.To omit the BOM, create a new XmlWriterSettings object and set the Encoding property to be a new UTF8Encoding object with the Boolean value in the constructor set to false.

Se aplica a

Create(XmlWriter, XmlWriterSettings)

Crea una nueva instancia de XmlWriter mediante los objetos XmlWriter y XmlWriterSettings especificados.Creates a new XmlWriter instance using the specified XmlWriter and XmlWriterSettings objects.

public:
 static System::Xml::XmlWriter ^ Create(System::Xml::XmlWriter ^ output, System::Xml::XmlWriterSettings ^ settings);
public static System.Xml.XmlWriter Create (System.Xml.XmlWriter output, System.Xml.XmlWriterSettings settings);
public static System.Xml.XmlWriter Create (System.Xml.XmlWriter output, System.Xml.XmlWriterSettings? settings);
static member Create : System.Xml.XmlWriter * System.Xml.XmlWriterSettings -> System.Xml.XmlWriter
Public Shared Function Create (output As XmlWriter, settings As XmlWriterSettings) As XmlWriter

Parámetros

output
XmlWriter

Objeto XmlWriter que desea utilizar como sistema de escritura subyacente.The XmlWriter object that you want to use as the underlying writer.

settings
XmlWriterSettings

Objeto XmlWriterSettings que se utiliza para configurar la nueva instancia de XmlWriter.The XmlWriterSettings object used to configure the new XmlWriter instance. Si es null, se utiliza un objeto XmlWriterSettings con la configuración predeterminada.If this is null, a XmlWriterSettings with default settings is used.

Si XmlWriter se está utilizando con el método Transform(String, XmlWriter), debe usar la propiedad OutputSettings para obtener un objeto XmlWriterSettings con la configuración correcta.If the XmlWriter is being used with the Transform(String, XmlWriter) method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. Con ello se garantiza que el objeto XmlWriter creado tenga la configuración de resultados correcta.This ensures that the created XmlWriter object has the correct output settings.

Devoluciones

XmlWriter

Objeto XmlWriter que contiene el objeto XmlWriter especificado.An XmlWriter object that is wrapped around the specified XmlWriter object.

Excepciones

El valor writer es null.The writer value is null.

Comentarios

Este método permite agregar características adicionales a un objeto subyacente XmlWriter .This method allows you add additional features to an underlying XmlWriter object. El XmlWriter objeto subyacente puede ser un objeto creado por el XmlWriter.Create método o un objeto creado mediante la XmlTextWriter implementación de.The underlying XmlWriter object can be an object created by the XmlWriter.Create method, or an object created using the XmlTextWriter implementation.

Se aplica a

Create(StringBuilder)

Crea una nueva instancia de XmlWriter mediante el objeto StringBuilder especificado.Creates a new XmlWriter instance using the specified StringBuilder.

public:
 static System::Xml::XmlWriter ^ Create(System::Text::StringBuilder ^ output);
public static System.Xml.XmlWriter Create (System.Text.StringBuilder output);
static member Create : System.Text.StringBuilder -> System.Xml.XmlWriter
Public Shared Function Create (output As StringBuilder) As XmlWriter

Parámetros

output
StringBuilder

StringBuilder en el que se va a escribir.The StringBuilder to which to write to. El contenido que escribe XmlWriter se anexa a StringBuilder.Content written by the XmlWriter is appended to the StringBuilder.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor builder es null.The builder value is null.

Comentarios

Cuando se usa esta sobrecarga, XmlWriterSettings se utiliza un objeto con la configuración predeterminada para crear el escritor XML.When you use this overload, an XmlWriterSettings object with default settings is used to create the XML writer.

ParámetroSetting DefaultDefault
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Dos espaciosTwo spaces
NamespaceHandling Default (sin eliminación)Default (no removal)
NewLineChars \r\n (retorno de carro, nueva línea)\r\n (carriage return, new line)
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Si desea especificar las características que se van a admitir en el escritor XML creado, utilice una sobrecarga que tome un XmlWriterSettings objeto como uno de sus argumentos y pase un XmlWriterSettings objeto con su configuración personalizada.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.

Se aplica a

Create(String)

Crea una nueva instancia de XmlWriter mediante el nombre de archivo especificado.Creates a new XmlWriter instance using the specified filename.

public:
 static System::Xml::XmlWriter ^ Create(System::String ^ outputFileName);
public static System.Xml.XmlWriter Create (string outputFileName);
static member Create : string -> System.Xml.XmlWriter
Public Shared Function Create (outputFileName As String) As XmlWriter

Parámetros

outputFileName
String

Archivo en el que desea escribir.The file to which you want to write. XmlWriter crea un archivo en la ruta de acceso especificada y lo escribe con la sintaxis de texto de XML 1.0.The XmlWriter creates a file at the specified path and writes to it in XML 1.0 text syntax. outputFileName debe ser una ruta del sistema de archivos.The outputFileName must be a file system path.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor url es null.The url value is null.

Ejemplos

En el ejemplo siguiente se crea un XmlWriter objeto y se escribe un nodo de libro.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();
}

Using writer As XmlWriter = XmlWriter.Create("output.xml")
  writer.WriteStartElement("book")
  writer.WriteElementString("price", "19.95")
  writer.WriteEndElement()
  writer.Flush()
End Using

Comentarios

Cuando se usa esta sobrecarga, XmlWriterSettings se utiliza un objeto con la configuración predeterminada para crear el escritor XML.When you use this overload, an XmlWriterSettings object with default settings is used to create the XML writer.

ParámetroSetting DefaultDefault
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Dos espaciosTwo spaces
NamespaceHandling Default (sin eliminación)Default (no removal)
NewLineChars \r\n (retorno de carro, nueva línea)\r\n (carriage return, new line)
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Si desea especificar las características que se van a admitir en el escritor XML creado, utilice una sobrecarga que tome un XmlWriterSettings objeto como uno de sus argumentos y pase un XmlWriterSettings objeto con su configuración personalizada.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.

Se aplica a

Create(TextWriter)

Crea una nueva instancia de XmlWriter mediante el objeto TextWriter especificado.Creates a new XmlWriter instance using the specified TextWriter.

public:
 static System::Xml::XmlWriter ^ Create(System::IO::TextWriter ^ output);
public static System.Xml.XmlWriter Create (System.IO.TextWriter output);
static member Create : System.IO.TextWriter -> System.Xml.XmlWriter
Public Shared Function Create (output As TextWriter) As XmlWriter

Parámetros

output
TextWriter

TextWriter en el que se desea escribir.The TextWriter to which you want to write. XmlWriter escribe la sintaxis de texto de XML 1.0 y la anexa al TextWriter especificado.The XmlWriter writes XML 1.0 text syntax and appends it to the specified TextWriter.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor text es null.The text value is null.

Ejemplos

En el ejemplo siguiente se crea un escritor que se envía a la consola.The following example creates a writer that outputs to the console.

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

Using writer As XmlWriter = XmlWriter.Create(Console.Out)
  writer.WriteStartElement("book")
  writer.WriteElementString("price", "19.95")
  writer.WriteEndElement()
  writer.Flush()
End Using

Comentarios

Cuando se usa esta sobrecarga, XmlWriterSettings se utiliza un objeto con la configuración predeterminada para crear el escritor XML.When you use this overload, an XmlWriterSettings object with default settings is used to create the XML writer.

ParámetroSetting DefaultDefault
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Dos espaciosTwo spaces
NamespaceHandling Default (sin eliminación)Default (no removal)
NewLineChars \r\n (retorno de carro, nueva línea)\r\n (carriage return, new line)
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Si desea especificar las características que se van a admitir en el escritor creado, use una sobrecarga que tome un XmlWriterSettings objeto como uno de sus argumentos y pase un XmlWriterSettings objeto con su configuración personalizada.If you want to specify the features to support on the created writer, use an overload that takes an XmlWriterSettings object as one of its arguments, and pass in an XmlWriterSettings object with your custom settings.

Se aplica a

Create(Stream)

Crea una nueva instancia de XmlWriter mediante la secuencia especificada.Creates a new XmlWriter instance using the specified stream.

public:
 static System::Xml::XmlWriter ^ Create(System::IO::Stream ^ output);
public static System.Xml.XmlWriter Create (System.IO.Stream output);
static member Create : System.IO.Stream -> System.Xml.XmlWriter
Public Shared Function Create (output As Stream) As XmlWriter

Parámetros

output
Stream

Flujo en el que desea escribir.The stream to which you want to write. XmlWriter escribe la sintaxis de texto de XML 1.0 y la anexa a la secuencia especificada.The XmlWriter writes XML 1.0 text syntax and appends it to the specified stream.

Devoluciones

XmlWriter

Un objeto XmlWriter.An XmlWriter object.

Excepciones

El valor stream es null.The stream value is null.

Ejemplos

En el ejemplo siguiente se escribe un fragmento XML en una secuencia de memoria.The following example writes an XML fragment to a memory stream. (Utiliza la Create(Stream, XmlWriterSettings) sobrecarga, que también configura los valores en la nueva instancia del escritor XML).(It uses the Create(Stream, XmlWriterSettings) overload, which also configures the settings on the new XML writer instance.)

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;

// Create the XmlWriter object and write some content.
MemoryStream strm = new MemoryStream();
XmlWriter writer = XmlWriter.Create(strm, settings);
writer.WriteElementString("orderID", "1-456-ab");
writer.WriteElementString("orderID", "2-36-00a");
writer.Flush();
writer.Close();

// Do additional processing on the stream.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.OmitXmlDeclaration = true
settings.ConformanceLevel = ConformanceLevel.Fragment
settings.CloseOutput = false

' Create the XmlWriter object and write some content.
Dim strm as MemoryStream = new MemoryStream()
Dim writer As XmlWriter = XmlWriter.Create(strm, settings)
writer.WriteElementString("orderID", "1-456-ab")
writer.WriteElementString("orderID", "2-36-00a")
writer.Flush()
writer.Close()

' Do additional processing on the stream.

Comentarios

Cuando se usa esta sobrecarga, XmlWriterSettings se usa un objeto con la siguiente configuración predeterminada para crear el escritor de XML:When you use this overload, an XmlWriterSettings object with the following default settings is used to create the XML writer:

ParámetroSetting DefaultDefault
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Dos espaciosTwo spaces
NamespaceHandling Default (sin eliminación)Default (no removal)
NewLineChars \r\n (retorno de carro, nueva línea)\r\n (carriage return, new line)
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Si desea especificar las características que se van a admitir en el escritor creado, use una sobrecarga que tome un XmlWriterSettings objeto como uno de sus argumentos y pase un XmlWriterSettings objeto con su configuración personalizada.If you want to specify the features to support on the created writer, use an overload that takes an XmlWriterSettings object as one of its arguments, and pass in an XmlWriterSettings object with your custom settings.

Además, XmlWriter siempre escribe una marca de orden de bytes (BOM) en el flujo de datos subyacente; sin embargo, algunas secuencias no deben tener una BOM.Also, XmlWriter always writes a Byte Order Mark (BOM) to the underlying data stream; however, some streams must not have a BOM. Para omitir la marca BOM, cree un nuevo XmlWriterSettings objeto y establezca la propiedad Encoding en un nuevo UTF8Encoding objeto con el valor booleano en el constructor establecido en false.To omit the BOM, create a new XmlWriterSettings object and set the Encoding property to be a new UTF8Encoding object with the Boolean value in the constructor set to false.

Se aplica a

Create(XmlWriter)

Crea una nueva instancia de XmlWriter mediante el objeto XmlWriter especificado.Creates a new XmlWriter instance using the specified XmlWriter object.

public:
 static System::Xml::XmlWriter ^ Create(System::Xml::XmlWriter ^ output);
public static System.Xml.XmlWriter Create (System.Xml.XmlWriter output);
static member Create : System.Xml.XmlWriter -> System.Xml.XmlWriter
Public Shared Function Create (output As XmlWriter) As XmlWriter

Parámetros

output
XmlWriter

Objeto XmlWriter que desea utilizar como sistema de escritura subyacente.The XmlWriter object that you want to use as the underlying writer.

Devoluciones

XmlWriter

Objeto XmlWriter que contiene el objeto XmlWriter especificado.An XmlWriter object that is wrapped around the specified XmlWriter object.

Excepciones

El valor writer es null.The writer value is null.

Comentarios

Este método permite agregar características a un objeto subyacente XmlWriter .This method allows you add features to an underlying XmlWriter object. El XmlWriter objeto subyacente puede ser un objeto creado por el XmlWriter.Create método o un objeto creado mediante la XmlTextWriter implementación de.The underlying XmlWriter object can be an object created by the XmlWriter.Create method, or an object created using the XmlTextWriter implementation.

Cuando se usa esta sobrecarga, XmlWriterSettings se utiliza un objeto con la configuración predeterminada para crear el escritor XML.When you use this overload, an XmlWriterSettings object with default settings is used to create the XML writer.

ParámetroSetting DefaultDefault
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Dos espaciosTwo spaces
NamespaceHandling Default (sin eliminación)Default (no removal)
NewLineChars \r\n (retorno de carro, nueva línea)\r\n (carriage return, new line)
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Si desea especificar las características que se van a admitir en el escritor XML creado, utilice una sobrecarga que tome un XmlWriterSettings objeto como uno de sus argumentos y pase un XmlWriterSettings objeto con su configuración personalizada.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.

Se aplica a