다음을 통해 공유


XmlDocument.CreateDocumentType 메서드

XmlDocumentType 개체를 반환합니다.

네임스페이스: System.Xml
어셈블리: System.Xml(system.xml.dll)

구문

‘선언
Public Overridable Function CreateDocumentType ( _
    name As String, _
    publicId As String, _
    systemId As String, _
    internalSubset As String _
) As XmlDocumentType
‘사용 방법
Dim instance As XmlDocument
Dim name As String
Dim publicId As String
Dim systemId As String
Dim internalSubset As String
Dim returnValue As XmlDocumentType

returnValue = instance.CreateDocumentType(name, publicId, systemId, internalSubset)
public virtual XmlDocumentType CreateDocumentType (
    string name,
    string publicId,
    string systemId,
    string internalSubset
)
public:
virtual XmlDocumentType^ CreateDocumentType (
    String^ name, 
    String^ publicId, 
    String^ systemId, 
    String^ internalSubset
)
public XmlDocumentType CreateDocumentType (
    String name, 
    String publicId, 
    String systemId, 
    String internalSubset
)
public function CreateDocumentType (
    name : String, 
    publicId : String, 
    systemId : String, 
    internalSubset : String
) : XmlDocumentType

매개 변수

  • name
    문서 형식의 이름입니다.
  • publicId
    문서 형식의 공용 식별자이거나 Null 참조(Visual Basic의 경우 Nothing)입니다. 공용 URI 또는 외부 DTD 하위 집합의 위치를 나타내는 시스템 식별자를 지정할 수 있습니다.
  • systemId
    문서 형식의 시스템 식별자이거나 Null 참조(Visual Basic의 경우 Nothing)입니다. 외부 DTD 하위 집합의 파일 위치를 지정하는 URL입니다.
  • internalSubset
    문서 형식의 DTD 내부 하위 집합이거나 Null 참조(Visual Basic의 경우 Nothing)입니다.

반환 값

XmlDocumentType입니다.

설명

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

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

W3C XML(Extensible Markup Language) 1.0 권장 사항(www.w3.org/TR/1998/REC-xml-19980210)에 따르면 DocumentType 노드는 Document 노드 안에서만 사용할 수 있습니다. 모든 XmlDocument에는 하나의 DocumentType 노드만 있을 수 있습니다. DocumentType 노드는 XmlDocument의 루트 요소 전에 삽입해야 합니다. 즉 문서에 이미 루트 요소가 있을 경우 DocumentType 노드를 추가할 수 없습니다.

전달된 매개 변수를 결합하여 올바른 XmlDocumentType을 구성하지 못한 경우 예외가 throw됩니다.

상속자 참고 사항 이 메서드에는 상속 요청이 있습니다. CreateDocumentType 메서드를 재정의하려면 완전 신뢰가 필요합니다. 자세한 내용은 상속 요청을 참조하십시오. 이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

예제

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

Option Explicit
Option Strict

Imports System
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 'Main
End Class 'Sample
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);
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   
   //Create a document type node and  
   //add it to the document.
   XmlDocumentType^ doctype;
   doctype = doc->CreateDocumentType( "book", nullptr, nullptr, "<!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 );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        //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.get_Out());
    } //main
} //Sample

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

XmlDocument 클래스
XmlDocument 멤버
System.Xml 네임스페이스