XmlWriter.Create Metodo

Definizione

Crea una nuova istanza di XmlWriter.

Overload

Nome Descrizione
Create(StringBuilder, XmlWriterSettings)

Crea una nuova XmlWriter istanza utilizzando gli StringBuilder oggetti e XmlWriterSettings .

Create(String, XmlWriterSettings)

Crea una nuova XmlWriter istanza usando il nome file e XmlWriterSettings l'oggetto .

Create(TextWriter, XmlWriterSettings)

Crea una nuova XmlWriter istanza utilizzando gli TextWriter oggetti e XmlWriterSettings .

Create(Stream, XmlWriterSettings)

Crea una nuova XmlWriter istanza usando il flusso e XmlWriterSettings l'oggetto .

Create(XmlWriter, XmlWriterSettings)

Crea una nuova XmlWriter istanza utilizzando gli oggetti e XmlWriter specificatiXmlWriterSettings.

Create(StringBuilder)

Crea una nuova XmlWriter istanza utilizzando l'oggetto specificato StringBuilder.

Create(String)

Crea una nuova XmlWriter istanza usando il nome file specificato.

Create(TextWriter)

Crea una nuova XmlWriter istanza utilizzando l'oggetto specificato TextWriter.

Create(Stream)

Crea una nuova XmlWriter istanza usando il flusso specificato.

Create(XmlWriter)

Crea una nuova XmlWriter istanza utilizzando l'oggetto specificato XmlWriter .

Commenti

Alcuni overload Create includono un settings parametro che accetta un XmlWriterSettings oggetto . È possibile usare questo oggetto per:

  • Specificare le funzionalità che si desidera supportare nell'oggetto creato XmlWriter .

  • Riutilizzare l'oggetto XmlWriterSettings per creare più oggetti writer. L'oggetto XmlWriterSettings viene copiato e contrassegnato come di sola lettura per ogni writer creato. Le modifiche apportate alle impostazioni in un'istanza XmlWriterSettings di non influiscono sui writer esistenti con le stesse impostazioni. È quindi possibile usare le stesse impostazioni per creare più writer con la stessa funzionalità. In alternativa, è possibile modificare le impostazioni in un'istanza XmlWriterSettings e creare un nuovo writer con un set di funzionalità diverso.

  • Aggiungere funzionalità a un writer XML esistente. Il Create metodo può accettare un altro XmlWriter oggetto. L'oggetto sottostante XmlWriter non deve essere un writer XML creato dal metodo statico Create . Ad esempio, è possibile specificare un writer XML definito dall'utente per aggiungere funzionalità aggiuntive.

  • Sfruttare appieno le funzionalità, ad esempio il controllo della conformità e la conformità migliori alla raccomandazione XML 1.0 disponibile solo per XmlWriter gli oggetti creati dal metodo statico Create .

Se si usa un Create overload che non accetta un XmlWriterSettings oggetto , vengono usate le impostazioni predefinite seguenti:

Setting Predefinito
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Due spazi
NamespaceHandling Default (nessuna rimozione)
NewLineChars \r\n (ritorno a capo, avanzamento riga) per piattaforme non Unix o \n (avanzamento riga) per le piattaforme Unix
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Note

Sebbene .NET Framework includa la classe , che è un'implementazione concreta della classe , è consigliabile creare istanze di /> .

Create(StringBuilder, XmlWriterSettings)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza utilizzando gli StringBuilder oggetti e XmlWriterSettings .

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

Parametri

output
StringBuilder

Oggetto StringBuilder in cui scrivere. Il contenuto scritto da XmlWriter viene aggiunto all'oggetto StringBuilder.

settings
XmlWriterSettings

Oggetto XmlWriterSettings utilizzato per configurare la nuova XmlWriter istanza. Se si tratta di null, viene usato un XmlWriterSettings oggetto con le impostazioni predefinite.

Se l'oggetto XmlWriter viene usato con il Transform(String, XmlWriter) metodo , è necessario utilizzare la OutputSettings proprietà per ottenere un XmlWriterSettings oggetto con le impostazioni corrette. In questo modo si garantisce che l'oggetto creato XmlWriter disponga delle impostazioni di output corrette.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

output è null.

Si applica a

Create(String, XmlWriterSettings)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza usando il nome file e XmlWriterSettings l'oggetto .

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

Parametri

outputFileName
String

File in cui si desidera scrivere. XmlWriter Crea un file nel percorso specificato e lo scrive nella sintassi di testo XML 1.0. Deve outputFileName essere un percorso del file system.

settings
XmlWriterSettings

Oggetto XmlWriterSettings utilizzato per configurare la nuova XmlWriter istanza. Se si tratta di null, viene usato un XmlWriterSettings oggetto con le impostazioni predefinite.

Se l'oggetto XmlWriter viene usato con il Transform(String, XmlWriter) metodo , è necessario utilizzare la OutputSettings proprietà per ottenere un XmlWriterSettings oggetto con le impostazioni corrette. In questo modo si garantisce che l'oggetto creato XmlWriter disponga delle impostazioni di output corrette.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

outputFileName è null.

Esempio

Nell'esempio seguente viene creato un XmlWriter oggetto con le impostazioni definite.

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

Si applica a

Create(TextWriter, XmlWriterSettings)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza utilizzando gli TextWriter oggetti e XmlWriterSettings .

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

Parametri

output
TextWriter

Oggetto TextWriter in cui si desidera scrivere. Scrive XmlWriter la sintassi di testo XML 1.0 e la aggiunge all'oggetto specificato TextWriter.

settings
XmlWriterSettings

Oggetto XmlWriterSettings utilizzato per configurare la nuova XmlWriter istanza. Se si tratta di null, viene usato un XmlWriterSettings oggetto con le impostazioni predefinite.

Se l'oggetto XmlWriter viene usato con il Transform(String, XmlWriter) metodo , è necessario utilizzare la OutputSettings proprietà per ottenere un XmlWriterSettings oggetto con le impostazioni corrette. In questo modo si garantisce che l'oggetto creato XmlWriter disponga delle impostazioni di output corrette.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

output è null.

Esempio

Nell'esempio seguente viene scrissa una stringa XML.

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

Si applica a

Create(Stream, XmlWriterSettings)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza usando il flusso e XmlWriterSettings l'oggetto .

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

Parametri

output
Stream

Flusso in cui si desidera scrivere. Scrive XmlWriter la sintassi di testo XML 1.0 e la aggiunge al flusso specificato.

settings
XmlWriterSettings

Oggetto XmlWriterSettings utilizzato per configurare la nuova XmlWriter istanza. Se si tratta di null, viene usato un XmlWriterSettings oggetto con le impostazioni predefinite.

Se l'oggetto XmlWriter viene usato con il Transform(String, XmlWriter) metodo , è necessario utilizzare la OutputSettings proprietà per ottenere un XmlWriterSettings oggetto con le impostazioni corrette. In questo modo si garantisce che l'oggetto creato XmlWriter disponga delle impostazioni di output corrette.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

output è null.

Esempio

Nell'esempio seguente viene scritto un frammento XML in un flusso di memoria.

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.

Commenti

XmlWriter scrive sempre un byte Order Mark (BOM) nel flusso di dati sottostante; tuttavia, alcuni flussi non devono avere una distinta base. Per omettere la distinta base, creare un nuovo XmlWriterSettings oggetto e impostare la proprietà Encoding come nuovo UTF8Encoding oggetto con il valore booleano nel costruttore impostato su false.

Si applica a

Create(XmlWriter, XmlWriterSettings)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza utilizzando gli oggetti e XmlWriter specificatiXmlWriterSettings.

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

Parametri

output
XmlWriter

Oggetto XmlWriter che si desidera utilizzare come writer sottostante.

settings
XmlWriterSettings

Oggetto XmlWriterSettings utilizzato per configurare la nuova XmlWriter istanza. Se si tratta di null, viene usato un XmlWriterSettings oggetto con le impostazioni predefinite.

Se l'oggetto XmlWriter viene usato con il Transform(String, XmlWriter) metodo , è necessario utilizzare la OutputSettings proprietà per ottenere un XmlWriterSettings oggetto con le impostazioni corrette. In questo modo si garantisce che l'oggetto creato XmlWriter disponga delle impostazioni di output corrette.

Valori restituiti

Oggetto XmlWriter di cui viene eseguito il wrapping intorno all'oggetto specificato XmlWriter .

Eccezioni

output è null.

Commenti

Questo metodo consente di aggiungere funzionalità aggiuntive a un oggetto sottostante XmlWriter . L'oggetto sottostante XmlWriter può essere un oggetto creato dal XmlWriter.Create metodo o un oggetto creato usando l'implementazione XmlTextWriter .

Si applica a

Create(StringBuilder)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza utilizzando l'oggetto specificato 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

Parametri

output
StringBuilder

Oggetto StringBuilder in cui scrivere. Il contenuto scritto da XmlWriter viene aggiunto all'oggetto StringBuilder.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

output è null.

Commenti

Quando si utilizza questo overload, viene usato un XmlWriterSettings oggetto con impostazioni predefinite per creare il writer XML.

Setting Predefinito
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Due spazi
NamespaceHandling Default (nessuna rimozione)
NewLineChars \r\n (ritorno a capo, avanzamento riga) per piattaforme non Unix o \n (avanzamento riga) per le piattaforme Unix
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Se si desidera specificare le funzionalità da supportare nel writer XML creato, utilizzare un overload che accetta un XmlWriterSettings oggetto come uno dei relativi argomenti e passare un XmlWriterSettings oggetto con le impostazioni personalizzate.

Si applica a

Create(String)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza usando il nome file specificato.

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

Parametri

outputFileName
String

File in cui si desidera scrivere. XmlWriter Crea un file nel percorso specificato e lo scrive nella sintassi di testo XML 1.0. Deve outputFileName essere un percorso del file system.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

outputFileName è null.

Esempio

Nell'esempio seguente viene creato un XmlWriter oggetto e viene scritto un nodo libro.

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

Commenti

Quando si utilizza questo overload, viene usato un XmlWriterSettings oggetto con impostazioni predefinite per creare il writer XML.

Setting Predefinito
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Due spazi
NamespaceHandling Default (nessuna rimozione)
NewLineChars \r\n (ritorno a capo, avanzamento riga) per piattaforme non Unix o \n (avanzamento riga) per le piattaforme Unix
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Se si desidera specificare le funzionalità da supportare nel writer XML creato, utilizzare un overload che accetta un XmlWriterSettings oggetto come uno dei relativi argomenti e passare un XmlWriterSettings oggetto con le impostazioni personalizzate.

Si applica a

Create(TextWriter)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza utilizzando l'oggetto specificato 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

Parametri

output
TextWriter

Oggetto TextWriter in cui si desidera scrivere. Scrive XmlWriter la sintassi di testo XML 1.0 e la aggiunge all'oggetto specificato TextWriter.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

output è null.

Esempio

Nell'esempio seguente viene creato un writer che restituisce la 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

Commenti

Quando si utilizza questo overload, viene usato un XmlWriterSettings oggetto con impostazioni predefinite per creare il writer XML.

Setting Predefinito
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Due spazi
NamespaceHandling Default (nessuna rimozione)
NewLineChars \r\n (ritorno a capo, avanzamento riga) per piattaforme non Unix o \n (avanzamento riga) per le piattaforme Unix
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Se si desidera specificare le funzionalità da supportare nel writer creato, usare un overload che accetta un XmlWriterSettings oggetto come uno dei relativi argomenti e passare un XmlWriterSettings oggetto con le impostazioni personalizzate.

Si applica a

Create(Stream)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza usando il flusso specificato.

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

Parametri

output
Stream

Flusso in cui si desidera scrivere. Scrive XmlWriter la sintassi di testo XML 1.0 e la aggiunge al flusso specificato.

Valori restituiti

Oggetto XmlWriter.

Eccezioni

output è null.

Esempio

Nell'esempio seguente viene scritto un frammento XML in un flusso di memoria. Usa l'overload Create(Stream, XmlWriterSettings) , che configura anche le impostazioni nella nuova istanza del writer XML.

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.

Commenti

Quando si utilizza questo overload, viene usato un XmlWriterSettings oggetto con le impostazioni predefinite seguenti per creare il writer XML:

Setting Predefinito
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Due spazi
NamespaceHandling Default (nessuna rimozione)
NewLineChars \r\n (ritorno a capo, avanzamento riga) per piattaforme non Unix o \n (avanzamento riga) per le piattaforme Unix
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Se si desidera specificare le funzionalità da supportare nel writer creato, usare un overload che accetta un XmlWriterSettings oggetto come uno dei relativi argomenti e passare un XmlWriterSettings oggetto con le impostazioni personalizzate.

Inoltre, XmlWriter scrive sempre un byte Order Mark (BOM) nel flusso di dati sottostante; tuttavia, alcuni flussi non devono avere una distinta base. Per omettere la distinta base, creare un nuovo XmlWriterSettings oggetto e impostare la proprietà Encoding come nuovo UTF8Encoding oggetto con il valore booleano nel costruttore impostato su false.

Si applica a

Create(XmlWriter)

Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs
Origine:
XmlWriter.cs

Crea una nuova XmlWriter istanza utilizzando l'oggetto specificato XmlWriter .

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

Parametri

output
XmlWriter

Oggetto XmlWriter che si desidera utilizzare come writer sottostante.

Valori restituiti

Oggetto XmlWriter di cui viene eseguito il wrapping intorno all'oggetto specificato XmlWriter .

Eccezioni

output è null.

Commenti

Questo metodo consente di aggiungere funzionalità a un oggetto sottostante XmlWriter . L'oggetto sottostante XmlWriter può essere un oggetto creato dal XmlWriter.Create metodo o un oggetto creato usando l'implementazione XmlTextWriter .

Quando si utilizza questo overload, viene usato un XmlWriterSettings oggetto con impostazioni predefinite per creare il writer XML.

Setting Predefinito
CheckCharacters true
CloseOutput false
ConformanceLevel ConformanceLevel.Document
Encoding Encoding.UTF8
Indent false
IndentChars Due spazi
NamespaceHandling Default (nessuna rimozione)
NewLineChars \r\n (ritorno a capo, avanzamento riga) per piattaforme non Unix o \n (avanzamento riga) per le piattaforme Unix
NewLineHandling NewLineHandling.Replace
NewLineOnAttributes false
OmitXmlDeclaration false
OutputMethod XmlOutputMethod.Xml
WriteEndDocumentOnClose true

Se si desidera specificare le funzionalità da supportare nel writer XML creato, utilizzare un overload che accetta un XmlWriterSettings oggetto come uno dei relativi argomenti e passare un XmlWriterSettings oggetto con le impostazioni personalizzate.

Si applica a