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

정의

지정된 이름 및 선택적 특성을 사용하여 DOCTYPE 선언을 씁니다.

public:
 override void WriteDocType(System::String ^ name, System::String ^ pubid, System::String ^ sysid, System::String ^ subset);
public override void WriteDocType(string name, string? pubid, string? sysid, string? subset);
public override void WriteDocType(string name, string pubid, string sysid, string subset);
override this.WriteDocType : string * string * string * string -> unit
Public Overrides 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

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

subset
String

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

예외

이 메서드는 프롤로그 외부에서 호출되었습니다(루트 요소 뒤).

name null 또는 String.Empty

-또는-

값이 name 잘못되면 XML이 잘못됩니다.

예제

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

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

public class Sample
{
  private const string filename = "sampledata.xml";

  public static void Main()
  {
     XmlTextWriter writer = null;

     writer = new XmlTextWriter (filename, null);
     //Use indenting for readability.
     writer.Formatting = Formatting.Indented;

     //Write the XML delcaration.
     writer.WriteStartDocument();

     //Write the ProcessingInstruction 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 a 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();

     //Load the file into an XmlDocument to ensure well formed XML.
     XmlDocument doc = new XmlDocument();
     //Preserve white space for readability.
     doc.PreserveWhitespace = true;
     //Load the file.
     doc.Load(filename);

     //Display the XML content to the console.
     Console.Write(doc.InnerXml);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    Private Shared filename As String = "sampledata.xml"
    Public Shared Sub Main()
        Dim writer As XmlTextWriter = Nothing
        
        writer = New XmlTextWriter(filename, Nothing)
        'Use indenting for readability.
        writer.Formatting = Formatting.Indented
        
        'Write the XML delcaration. 
        writer.WriteStartDocument()
        
        'Write the ProcessingInstruction 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 a 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()
        
        'Load the file into an XmlDocument to ensure well formed XML.
        Dim doc As New XmlDocument()
        'Preserve white space for readability.
        doc.PreserveWhitespace = True
        'Load the file.
        doc.Load(filename)
        
        'Display the XML content to the console.
        Console.Write(doc.InnerXml)
    End Sub
End Class

설명

메모

새로운 기능을 활용하기 위해 XmlWriter 인스턴스를 XmlWriter.Create 메서드를 사용하고 XmlWriterSettings 클래스를 활용하여 만드는 것을 권장합니다.

이 메서드는 또는 .에 잘못된 문자가 pubidsysidsubset있는지 확인하지 않습니다. 또한 내부 하위 집합이 올바른 형식인지는 확인하지 않습니다.

Important

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

적용 대상