Прочитать на английском

Поделиться через


XDocumentType.NodeType Свойство

Определение

Возвращает тип узла для этого узла.

public override System.Xml.XmlNodeType NodeType { get; }

Значение свойства

XmlNodeType

Тип узла. Для объектов XDocumentType это значение равно DocumentType.

Примеры

В следующем примере показано использование этого свойства для получения типа узла для 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.DocumentType.NodeType);  

В этом примере выводятся следующие данные:

DocumentType  

Комментарии

Поскольку все классы, производные от XObject свойства NodeType , можно написать код, который работает с коллекциями конкретных подклассов XObject. Затем код может проверить тип узла каждого узла в коллекции.

Применяется к

Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

См. также раздел