XmlNodeList.Item(Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定されたインデックス位置にあるノードを取得します。
public:
abstract System::Xml::XmlNode ^ Item(int index);
public abstract System.Xml.XmlNode Item(int index);
public abstract System.Xml.XmlNode? Item(int index);
abstract member Item : int -> System.Xml.XmlNode
Public MustOverride Function Item (index As Integer) As XmlNode
パラメーター
- index
- Int32
ノードの一覧への 0 から始まるインデックス。
返品
コレクション内の指定したインデックスを持つ XmlNode 。
indexがリスト内のノード数以上の場合は、nullが返されます。
例
次の例では、 XmlNodeList内の 2 番目のノードを取得して表示します。
using System;
using System.IO;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<items>" +
" <item>First item</item>" +
" <item>Second item</item>" +
"</items>");
//Get and display the last item node.
XmlElement root = doc.DocumentElement;
XmlNodeList nodeList = root.GetElementsByTagName("item");
Console.WriteLine(nodeList.Item(1).InnerXml);
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<items>" & _
" <item>First item</item>" & _
" <item>Second item</item>" & _
"</items>")
'Get and display the last item node.
Dim root as XmlElement = doc.DocumentElement
Dim nodeList as XmlNodeList = root.GetElementsByTagName("item")
Console.WriteLine(nodeList.Item(1).InnerXml)
end sub
end class