XmlWriter.Close 메서드

정의

파생 클래스에서 재정의된 경우 이 스트림과 기본 스트림을 닫습니다.

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 ()

예외

호출된 후 Close 더 많은 출력을 작성하도록 호출되거나 이 호출의 결과가 잘못된 XML 문서입니다.

-또는-

XmlWriter 이전 비동기 작업이 완료되기 전에 메서드가 호출되었습니다. 이 경우 InvalidOperationException "비동기 작업이 이미 진행 중입니다."라는 메시지와 함께 throw됩니다.

예제

다음 예제에서는 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

설명

열려 있는 모든 요소 또는 특성은 자동으로 닫힙니다.

메모

메서드를 XmlWriter 사용하여 XML을 출력하는 경우 메서드를 호출할 때까지 요소와 특성이 Close 기록되지 않습니다. 예를 들어 XmlWriter를 사용하여 닫XmlDocument을 때까지 XmlWriter를 XmlWriter채우는 경우 대상 문서에서 작성된 요소와 특성을 관찰할 수 없습니다.

적용 대상