XmlWriter.WriteEndDocument XmlWriter.WriteEndDocument XmlWriter.WriteEndDocument XmlWriter.WriteEndDocument Method

정의

파생 클래스에서 재정의되면 열려 있는 모든 요소나 특성을 닫고 작성기를 다시 시작 상태로 설정합니다.When overridden in a derived class, closes any open elements or attributes and puts the writer back in the Start state.

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

예외

XML 문서가 잘못된 경우The XML document is invalid.

이전 비동기 작업이 완료되기 전에 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 file representing a book.

using System;
using System.IO;
using System.Xml;

public class Sample {

  private const string filename = "sampledata.xml";

  public static void Main() {
  
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     XmlWriter writer = XmlWriter.Create(filename, settings);

     // Write the Processing Instruction node.
     String PItext="type=\"text/xsl\" href=\"book.xsl\"";
     writer.WriteProcessingInstruction("xml-stylesheet", PItext);

     // Write the DocumentType node.
     writer.WriteDocType("book", null , null, "<!ENTITY h \"hardcover\">");
        
     // Write a Comment node.
     writer.WriteComment("sample XML");
    
     // Write the root element.
     writer.WriteStartElement("book");

     // Write the genre attribute.
     writer.WriteAttributeString("genre", "novel");
    
     // Write the ISBN attribute.
     writer.WriteAttributeString("ISBN", "1-8630-014");

     // Write the title.
     writer.WriteElementString("title", "The Handmaid's Tale");
              
     // Write the style element.
     writer.WriteStartElement("style");
     writer.WriteEntityRef("h");
     writer.WriteEndElement(); 

     // Write the price.
     writer.WriteElementString("price", "19.95");

     // Write CDATA.
     writer.WriteCData("Prices 15% off!!");

     // Write the close tag for the root element.
     writer.WriteEndElement();
             
     writer.WriteEndDocument();

     // Write the XML to file and close the writer.
     writer.Flush();
     writer.Close();  
  }

}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
    Private Const filename As String = "sampledata.xml"
    
  Public Shared Sub Main()

     Dim settings As XmlWriterSettings = new XmlWriterSettings()
     settings.Indent = true
     Dim writer As XmlWriter = XmlWriter.Create(filename, settings)
        
     ' Write the Processing Instruction node.
     Dim PItext As String = "type=""text/xsl"" href=""book.xsl"""
     writer.WriteProcessingInstruction("xml-stylesheet", PItext)
        
     'Write the DocumentType node.
     writer.WriteDocType("book", Nothing, Nothing, "<!ENTITY h ""hardcover"">")
        
     ' Write a Comment node.
     writer.WriteComment("sample XML")
        
     ' Write the root element.
     writer.WriteStartElement("book")
        
     ' Write the genre attribute
     writer.WriteAttributeString("genre", "novel")
        
     ' Write the ISBN attribute.
     writer.WriteAttributeString("ISBN", "1-8630-014")
        
     ' Write the title.
     writer.WriteElementString("title", "The Handmaid's Tale")
        
     ' Write the style element.
     writer.WriteStartElement("style")
     writer.WriteEntityRef("h")
     writer.WriteEndElement()
       
     ' Write the price.
     writer.WriteElementString("price", "19.95")
        
     ' Write CDATA.
     writer.WriteCData("Prices 15% off!!")
        
     ' Write the close tag for the root element.
     writer.WriteEndElement()
        
     writer.WriteEndDocument()
        
     ' Write the XML to file and close the writer
     writer.Flush()
     writer.Close()
        
    End Sub
End Class

설명

참고

사용 하는 경우는 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.

이 메서드의 비동기 버전을 참조 하세요. WriteEndDocumentAsync합니다.For the asynchronous version of this method, see WriteEndDocumentAsync.

적용 대상