XmlWriter.Close Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Quando sobreposto numa classe derivada, fecha este fluxo e o fluxo subjacente.
public:
virtual void Close();
public:
abstract void Close();
public virtual void Close();
public abstract void Close();
abstract member Close : unit -> unit
override this.Close : unit -> unit
abstract member Close : unit -> unit
Public Overridable Sub Close ()
Public MustOverride Sub Close ()
Exceções
É feita uma chamada para escrever mais saída depois de Close ter sido chamada ou o resultado dessa chamada é um documento XML inválido.
-ou-
Um XmlWriter método era chamado antes de uma operação assíncrona anterior terminar. Neste caso, InvalidOperationException é lançado com a mensagem "Uma operação assíncrona já está em curso."
Exemplos
O exemplo seguinte escreve um nó XML.
using System;
using System.IO;
using System.Xml;
public class Sample {
public static void Main() {
// Create a writer to write XML to the console.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
XmlWriter writer = XmlWriter.Create(Console.Out, settings);
// Write the book element.
writer.WriteStartElement("book");
// Write the title element.
writer.WriteStartElement("title");
writer.WriteString("Pride And Prejudice");
writer.WriteEndElement();
// Write the close tag for the root element.
writer.WriteEndElement();
// Write the XML and close the writer.
writer.Close();
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
' Create a writer to write XML to the console.
Dim settings As XmlWriterSettings = new XmlWriterSettings()
settings.Indent = true
settings.OmitXmlDeclaration = true
Dim writer As XmlWriter = XmlWriter.Create(Console.Out, settings)
' Write the book element.
writer.WriteStartElement("book")
' Write the title element.
writer.WriteStartElement("title")
writer.WriteString("Pride And Prejudice")
writer.WriteEndElement()
' Write the close tag for the root element.
writer.WriteEndElement()
' Write the XML and close the writer.
writer.Close()
End Sub
End Class
Observações
Quaisquer elementos ou atributos deixados em aberto são automaticamente fechados.
Note
Quando usas os XmlWriter métodos para produzir XML, os elementos e atributos não serão escritos até chamares o Close método. Por exemplo, se estiver a usar o XmlWriter para preencher um XmlDocument, até fechar o XmlWriter, não conseguirá observar os elementos e atributos escritos no documento de destino.