XmlWriter.WriteDocType(String, String, String, String) 메서드

정의

파생 클래스에서 재정의되면 지정된 이름 및 선택적 특성이 있는 DOCTYPE 선언을 작성합니다.

public:
 abstract void WriteDocType(System::String ^ name, System::String ^ pubid, System::String ^ sysid, System::String ^ subset);
public abstract void WriteDocType (string name, string pubid, string sysid, string subset);
public abstract void WriteDocType (string name, string? pubid, string? sysid, string? subset);
abstract member WriteDocType : string * string * string * string -> unit
Public MustOverride Sub WriteDocType (name As String, pubid As String, sysid As String, subset As String)

매개 변수

name
String

DOCTYPE의 이름입니다. 이 이름은 비어 있지 않아야 합니다.

pubid
String

null이 아닌 경우 PUBLIC "pubid" "sysid"도 씁니다. 여기서 pubidsysid는 지정된 인수 값으로 바뀝니다.

sysid
String

pubidnull이고 sysid가 null이 아닌 경우 SYSTEM "sysid"를 씁니다. 여기서 sysid는 이 인수 값으로 바뀝니다.

subset
String

null이 아닌 경우 하위 집합이 이 인수 값으로 대체되는 [subset]을 작성합니다.

예외

이 메서드가 루트 요소 다음의 프롤로그 외부에서 호출된 경우

또는

이전 비동기 작업이 완료되기 전에 XmlWriter 메서드가 호출되었습니다. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.

name의 값이 잘못된 XML이 되는 경우

예제

다음 예제에서는 책을 나타내는 XML 파일을 씁니다.

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

설명

이 메서드는 또는 sysidsubset에서 pubid잘못된 문자를 확인하지 않습니다. 내부 하위 집합이 올바른 형식인지도 확인하지 않습니다.

중요

XmlWriter 메서드에 전달되는 데이터의 유효성을 WriteDocType 검사하지 않습니다. 이 메서드에 임의의 데이터를 전달해서는 안 됩니다.

이 메서드의 비동기 버전은 를 참조하세요 WriteDocTypeAsync.

적용 대상