XDocument.DocumentType 속성

정의

이 문서의 DTD(문서 종류 정의)를 가져옵니다.

public:
 property System::Xml::Linq::XDocumentType ^ DocumentType { System::Xml::Linq::XDocumentType ^ get(); };
public System.Xml.Linq.XDocumentType DocumentType { get; }
public System.Xml.Linq.XDocumentType? DocumentType { get; }
member this.DocumentType : System.Xml.Linq.XDocumentType
Public ReadOnly Property DocumentType As XDocumentType

속성 값

XDocumentType

이 문서의 DTD가 들어 있는 XDocumentType입니다.

예제

다음 예제에서는 을 포함하는 문서를 만듭니다 XDocumentType.

Visual Basic XML 리터럴 내에서 문서 형식을 지원하지 않습니다. 그러나 먼저 XML 리터럴을 사용하여 문서를 만든 다음 XML 트리의 적절한 위치에 노드를 만들고 추가하여 XDocumentType 문서 형식이 포함된 문서를 만들 수 있습니다.

string internalSubset = @"<!ELEMENT Pubs (Book+)>  
<!ELEMENT Book (Title, Author)>  
<!ELEMENT Title (#PCDATA)>  
<!ELEMENT Author (#PCDATA)>";  

string target = "xml-stylesheet";  
string data = "href='mystyle.css' title='Compact' type='text/css'";  

XDocument doc = new XDocument(  
    new XComment("This is a comment."),  
    new XProcessingInstruction(target, data),  
    new XDocumentType("Pubs", null, null, internalSubset),  
    new XElement("Pubs",   
        new XElement("Book",  
            new XElement("Title", "Artifacts of Roman Civilization"),  
            new XElement("Author", "Moreno, Jordao")  
        ),  
        new XElement("Book",  
            new XElement("Title", "Midieval Tools and Implements"),  
            new XElement("Author", "Gazit, Inbar")  
        )  
    ),  
    new XComment("This is another comment.")  
);  
doc.Declaration = new XDeclaration("1.0", "utf-8", "true");  
Console.WriteLine(doc);  

doc.Save("test.xml");  
Dim internalSubset = _  
        "<!ELEMENT Pubs (Book+)>" & Environment.NewLine & _  
        "<!ELEMENT Book (Title, Author)>" & Environment.NewLine & _  
        "<!ELEMENT Title (#PCDATA)>" & Environment.NewLine & _  
        "<!ELEMENT Author (#PCDATA)>"  

Dim doc As XDocument = _  
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
    <!--This is a comment.-->  
    <?xml-stylesheet href='mystyle.css' title='Compact' type='text/css'?>  
    <Pubs>  
        <Book>  
            <Title>Artifacts of Roman Civilization</Title>  
            <Author>Moreno, Jordao</Author>  
        </Book>  
        <Book>  
            <Title>Midieval Tools and Implements</Title>  
            <Author>Gazit, Inbar</Author>  
        </Book>  
    </Pubs>  
    <!--This is another comment.-->  

doc.Nodes().Skip(1).First().AddAfterSelf(New XDocumentType("Pubs", Nothing, Nothing, internalSubset))  
Console.WriteLine(doc)  

이 예제는 다음과 같은 출력을 생성합니다.

<!--This is a comment.-->  
<?xml-stylesheet href='mystyle.css' title='Compact' type='text/css'?>  
<!DOCTYPE Pubs [<!ELEMENT Pubs (Book+)>  
<!ELEMENT Book (Title, Author)>  
<!ELEMENT Title (#PCDATA)>  
<!ELEMENT Author (#PCDATA)>]>  
<Pubs>  
  <Book>  
    <Title>Artifacts of Roman Civilization</Title>  
    <Author>Moreno, Jordao</Author>  
  </Book>  
  <Book>  
    <Title>Midieval Tools and Implements</Title>  
    <Author>Gazit, Inbar</Author>  
  </Book>  
</Pubs>  
<!--This is another comment.-->  

설명

LINQ to XML DTD에 대한 제한된 지원을 제공합니다.

XML 트리를 DTD가 포함된 XML 문서로 채울 수 있습니다. 그러면 XML 트리에 노드가 DocumentType 포함됩니다. 트리를 직렬화하거나 저장하면 DTD도 직렬화됩니다. LINQ to XML DTD의 모든 엔터티를 확장합니다. XML 트리를 직렬화하거나 저장하면 엔터티 참조가 저장되지 않습니다. 대신, 노드는 엔터티의 텍스트로 대체된 엔터티 참조로 저장됩니다.

DTD에 기본 특성이 포함되어 있으면 XML 트리에서 특성이 일반 특성으로 만들어집니다.

기본적으로 LINQ to XML DTD에 따라 문서의 유효성을 검사하지 않습니다. DTD를 기반으로 문서의 유효성을 검사하려면 DTD를 기반으로 유효성을 검사할 문서를 만든 XmlReader 다음, DTD에서 XML 트리를 XmlReader만듭니다.

적용 대상

추가 정보