XmlNodeList.ItemOf プロパティ
指定したインデックス位置にあるノードを取得します。
[C#] C# では、このプロパティは XmlNodeList クラスのインデクサになります。
Public Overridable Default ReadOnly Property ItemOf( _
ByVal i As Integer _) As XmlNode
[C#]
public virtual XmlNode this[inti] {get;}
[C++]
public: __property virtual XmlNode* get_ItemOf(inti);
[JScript]
returnValue = XmlNodeListObject.ItemOf(i);またはreturnValue = XmlNodeListObject(i);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- i
ノードのリストの 0 から始まるインデックス番号。
パラメータ [Visual Basic, C#, C++]
- i
ノードのリストの 0 から始まるインデックス番号。
プロパティ値
コレクション内の XmlNode 。インデックスがリスト内のノード数以上の場合は、 null 参照 (Visual Basic では Nothing) を返します。
使用例
[Visual Basic, C#, C++] XmlDocument オブジェクトを作成し、 GetElementsByTagName メソッドとその結果の XmlNodeList を使用して、すべての書籍のタイトルを表示する例を次に示します。
Imports System
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
[C#]
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);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument* doc = new XmlDocument();
doc->Load(S"2books.xml");
// Get and display all the book titles.
XmlElement* root = doc->DocumentElement;
XmlNodeList* elemList = root->GetElementsByTagName(S"title");
for (int i=0; i < elemList->Count; i++)
{
Console::WriteLine(elemList->ItemOf[i]->InnerXml);
}
}
この例では、入力として、 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>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ