XmlNodeList.Count 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 XmlNodeList
中的節點數目。
public:
abstract property int Count { int get(); };
public abstract int Count { get; }
member this.Count : int
Public MustOverride ReadOnly Property Count As Integer
屬性值
XmlNodeList
中的節點數目。
範例
下列範例會 XmlDocument 建立 物件,並使用 GetElementsByTagName 方法和結果 XmlNodeList
來顯示所有書籍標題。
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew XmlDocument;
doc->Load( "2books.xml" );
// Get and display all the book titles.
XmlElement^ root = doc->DocumentElement;
XmlNodeList^ elemList = root->GetElementsByTagName( "title" );
for ( int i = 0; i < elemList->Count; i++ )
{
Console::WriteLine( elemList[ i ]->InnerXml );
}
}
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("2books.xml");
// Get and display all the book titles.
XmlElement root = doc.DocumentElement;
XmlNodeList elemList = root.GetElementsByTagName("title");
for (int i=0; i < elemList.Count; i++)
{
Console.WriteLine(elemList[i].InnerXml);
}
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.Load("2books.xml")
' Get and display all the book titles.
Dim root as XmlElement = doc.DocumentElement
Dim elemList as XmlNodeList = root.GetElementsByTagName("title")
Dim i as integer
for i=0 to elemList.Count-1
Console.WriteLine(elemList.ItemOf(i).InnerXml)
next
end sub
end class
此範例會使用 檔案 2books.xml
作為輸入。
<!--sample XML fragment-->
<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>