XDocument.DocumentType Özellik

Tanım

Bu belge için Belge Türü Tanımını (DTD) alır.

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

Özellik Değeri

XDocumentType

XDocumentType Bu belgenin DTD'sini içeren bir.

Örnekler

Aşağıdaki örnek, içeren XDocumentTypebir belge oluşturur.

Visual Basic XML değişmez değerleri içindeki belge türlerini desteklemez. Ancak, önce XML değişmez değerlerini kullanarak belgeyi oluşturarak ve sonra XML ağacında uygun bir yerde düğüm oluşturup ekleyerek belge türünü içeren bir XDocumentType belge oluşturmak mümkündür.

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)  

Bu örnek aşağıdaki çıkışı oluşturur:

<!--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.-->  

Açıklamalar

LINQ to XML, DTD'ler için sınırlı destek sağlar.

XML ağacını DTD içeren bir XML belgesiyle doldurabilirsiniz. Xml ağacı daha sonra bir DocumentType düğüm içerir. Ağacı seri hale getirdiğinizde veya kaydettiğinizde, DTD de seri hale getirilir. LINQ to XML DTD'deki tüm varlıkları genişletir. XML ağacını seri hale getirdiğinizde veya kaydettiğinizde, varlık başvuruları kaydedilmez; bunun yerine düğümler varlık başvuruları ile kaydedilir ve varlık metniyle değiştirilir.

DTD varsayılan öznitelikler içeriyorsa, öznitelikler XML ağacında sıradan öznitelikler olarak oluşturulur.

Varsayılan olarak, LINQ to XML bir belgeyi DTD'sine göre doğrulamaz. DTD tabanlı bir belgeyi doğrulamak için, XmlReader bir DTD'yi temel alarak doğrulayacak bir oluşturun ve ardından öğesinden XmlReaderbir XML ağacı oluşturun.

Şunlara uygulanır

Ayrıca bkz.