XmlNodeList.ItemOf[Int32] XmlNodeList.ItemOf[Int32] XmlNodeList.ItemOf[Int32] XmlNodeList.ItemOf[Int32] Property

定義

取得指定之索引位置的節點。Gets a node at the given index.

public:
 virtual property System::Xml::XmlNode ^ default[int] { System::Xml::XmlNode ^ get(int i); };
public virtual System.Xml.XmlNode this[int i] { get; }
member this.ItemOf(int) : System.Xml.XmlNode
Default Public Overridable ReadOnly Property ItemOf(i As Integer) As XmlNode

參數

i
Int32 Int32 Int32 Int32

在節點清單中以零起始的索引。The zero-based index into the list of nodes.

屬性值

在集合中具有指定的索引的 XmlNodeThe XmlNode with the specified index in the collection. 如果索引大於或等於清單中節點的數目,則會傳回 nullIf index is greater than or equal to the number of nodes in the list, this returns null.

範例

下列範例會建立XmlDocument物件, 並GetElementsByTagName使用方法和產生XmlNodeList的來顯示所有書名。The following example creates an XmlDocument object and uses the GetElementsByTagName method and the resulting XmlNodeList to display all the book titles.

#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檔案做為輸入。The example uses the file 2books.xml as input.

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

適用於