XCData.NodeType Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan jenis node untuk simpul ini.
public:
virtual property System::Xml::XmlNodeType NodeType { System::Xml::XmlNodeType get(); };
public override System.Xml.XmlNodeType NodeType { get; }
member this.NodeType : System.Xml.XmlNodeType
Public Overrides ReadOnly Property NodeType As XmlNodeType
Nilai Properti
Jenis node. Untuk XCData objek, nilai ini adalah CDATA.
Contoh
Contoh berikut membuat pohon XML yang berisi berbagai jenis simpul. Kemudian iterasi melalui pohon, dan mencetak jenis node dari setiap simpul.
// Note that XNode uses XmlNodeType, which is in the System.Xml namespace.
XDocument xmlTree = new XDocument(
new XComment("a comment"),
new XProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"hello.xsl\""),
new XElement("Root",
new XAttribute("Att", "attContent"),
new XElement("Child1",
new XCData("CDATA content")
),
new XElement("Child2",
new XText("Text content")
)
)
);
foreach (XNode node in xmlTree.DescendantNodes())
{
Console.WriteLine(node.NodeType);
if (node.NodeType == XmlNodeType.Element)
{
foreach (XAttribute att in ((XElement)node).Attributes())
Console.WriteLine(att.NodeType);
}
}
Dim xmlTree As XDocument = _
<?xml version="1.0" encoding="utf-8"?>
<!--a comment-->
<?xml-stylesheet type='text/xsl' href='hello.xsl'?>
<Root Att="attContent">
<Child1><![CDATA[CDATA content]]></Child1>
<Child2>Text content</Child2>
</Root>
' Note that XNode uses XmlNodeType, which is in the System.Xml namespace.
For Each node As XNode In xmlTree.DescendantNodes
Console.WriteLine(node.NodeType.ToString())
If node.NodeType = XmlNodeType.Element Then
For Each att In DirectCast(node, XElement).Attributes
Console.WriteLine(att.NodeType.ToString())
Next
End If
Next
Contoh ini menghasilkan output berikut:
Comment
ProcessingInstruction
Element
Attribute
Element
CDATA
Element
Text
Keterangan
Karena semua kelas yang berasal dari XObject berisi NodeType properti, Anda dapat menulis kode yang beroperasi pada koleksi subkelas konkret .XObject Kode Anda kemudian dapat menguji jenis node dari setiap simpul dalam koleksi.