다음을 통해 공유


XmlDocument.CreateDocumentType(String, String, String, String) 메서드

정의

XmlDocumentType 개체를 반환합니다.

public:
 virtual System::Xml::XmlDocumentType ^ CreateDocumentType(System::String ^ name, System::String ^ publicId, System::String ^ systemId, System::String ^ internalSubset);
public virtual System.Xml.XmlDocumentType CreateDocumentType(string name, string? publicId, string? systemId, string? internalSubset);
public virtual System.Xml.XmlDocumentType CreateDocumentType(string name, string publicId, string systemId, string internalSubset);
abstract member CreateDocumentType : string * string * string * string -> System.Xml.XmlDocumentType
override this.CreateDocumentType : string * string * string * string -> System.Xml.XmlDocumentType
Public Overridable Function CreateDocumentType (name As String, publicId As String, systemId As String, internalSubset As String) As XmlDocumentType

매개 변수

name
String

문서 형식의 이름입니다.

publicId
String

문서 형식 또는 null.의 공용 식별자입니다. 공용 URI 및 시스템 식별자를 지정하여 외부 DTD 하위 집합의 위치를 식별할 수도 있습니다.

systemId
String

문서 형식 또는 null.의 시스템 식별자입니다. 외부 DTD 하위 집합에 대한 파일 위치의 URL을 지정합니다.

internalSubset
String

문서 형식 또는 null.의 DTD 내부 하위 집합입니다.

반환

XmlDocumentType.

예제

다음 예제에서는 DocumentType 노드를 만들고 XML 문서에 추가합니다.

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

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();

    //Create a document type node and
    //add it to the document.
    XmlDocumentType doctype;
    doctype = doc.CreateDocumentType("book", null, null, "<!ELEMENT book ANY>");
    doc.AppendChild(doctype);

    //Create the root element and
    //add it to the document.
    doc.AppendChild(doc.CreateElement("book"));

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        
        'Create a document type node and  
        'add it to the document.
        Dim doctype As XmlDocumentType
        doctype = doc.CreateDocumentType("book", Nothing, Nothing, "<!ELEMENT book ANY>")
        doc.AppendChild(doctype)
        
        'Create the root element and 
        'add it to the document.
        doc.AppendChild(doc.CreateElement("book"))
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class

설명

반환된 노드에는 구문 분석 및 EntitiesNotations 컬렉션이 있습니다.

이 메서드는 문서의 컨텍스트에서 새 개체를 만들지만 문서 트리에 새 개체를 자동으로 추가하지는 않습니다. 새 개체를 추가하려면 노드 삽입 메서드 중 하나를 명시적으로 호출해야 합니다.

W3C XML(Extensible Markup Language) 1.0 권장 사항에 따라 DocumentType 노드는 문서 노드 내에서만 허용됩니다. 각 XmlDocument 노드에는 DocumentType 노드가 하나만 있을 수 있습니다. DocumentType 노드도 문서의 루트 요소 앞에 삽입해야 합니다(문서에 루트 요소가 XmlDocument 이미 있는 경우 DocumentType 노드를 추가할 수 없음). 전달된 매개 변수가 결합되어 유효한 XmlDocumentType매개 변수를 작성하지 않으면 예외가 throw됩니다.

상속자 참고

이 메서드에는 상속 요청이 있습니다. 메서드를 재정의하려면 완전 신뢰가 CreateDocumentType 필요합니다.

이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

적용 대상