XmlWriter.Close XmlWriter.Close XmlWriter.Close XmlWriter.Close Method

정의

파생 클래스에서 재정의되면 이 스트림 및 내부 스트림을 닫습니다.When overridden in a derived class, closes this stream and the underlying stream.

public:
 abstract void Close();
public abstract void Close ();
abstract member Close : unit -> unit
Public MustOverride Sub Close ()

예외

Close가 호출된 후 호출하여 더 많은 출력을 작성하거나 이 호출 결과가 잘못된 XML 문서인 경우A call is made to write more output after Close has been called or the result of this call is an invalid XML document.

또는-or-

이전 비동기 작업이 완료되기 전에 XmlWriter 메서드가 호출되었습니다.An XmlWriter method was called before a previous asynchronous operation finished. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

예제

다음 예제에서는 XML 노드를 씁니다.The following example writes an XML node.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create a writer to write XML to the console.
   XmlWriterSettings^ settings = gcnew XmlWriterSettings;
   settings->Indent = true;
   settings->OmitXmlDeclaration = true;
   XmlWriter^ writer = XmlWriter::Create( Console::Out, settings );
   
   // Write the book element.
   writer->WriteStartElement( L"book" );
   
   // Write the title element.
   writer->WriteStartElement( L"title" );
   writer->WriteString( L"Pride And Prejudice" );
   writer->WriteEndElement();
   
   // Write the close tag for the root element.
   writer->WriteEndElement();
   
   // Write the XML and close the writer.
   writer->Close();
   return 1;
}

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 'Main 
End Class 'Sample

설명

모든 요소 또는 특성 열려 자동으로 닫힙니다.Any elements or attributes left open are automatically closed.

참고

사용 하는 경우는 XmlWriter XML 요소 및 특성을 출력 하는 메서드를 호출 하기 전에 기록 되지 것입니다는 Close 메서드.When you use the XmlWriter methods to output XML, the elements and attributes will not be written until you call the Close method. 예를 들어, 채우는 XmlWriter를 사용 하는 경우는 XmlDocument닫을 때까지는 XmlWriter, 작성 된 요소 및 대상 문서에 특성을 확인할 수 없습니다.For example, if you are using the XmlWriter to populate an XmlDocument, until you close the XmlWriter, you will not be able to observe the written elements and attributes in the target document.

적용 대상