XmlWriter.WriteDocType(String, String, String, String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파생 클래스에서 재정의되는 경우 지정된 이름 및 선택적 특성을 사용하여 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
null이 pubid 아닌 null 경우 sysid SYSTEM "sysid"를 씁니다. 여기서 sysid 이 인수의 값으로 바뀝니다.
- subset
- String
null이 아닌 경우 하위 집합이 이 인수의 값으로 대체되는 [하위 집합]을 씁니다.
예외
이 메서드는 프롤로그 외부에서 호출되었습니다(루트 요소 뒤).
-또는-
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
설명
이 메서드는 또는 .에 잘못된 문자가 pubidsysidsubset있는지 확인하지 않습니다. 또한 내부 하위 집합이 올바른 형식인지는 확인하지 않습니다.
Important
메서드 XmlWriter 에 전달되는 WriteDocType 데이터의 유효성을 검사하지 않습니다. 이 메서드에 임의의 데이터를 전달하면 안 됩니다.
이 메서드의 비동기 버전은 다음을 참조하세요 WriteDocTypeAsync.