次の方法で共有


XmlNamedNodeMap.Item メソッド

XmlNamedNodeMap 内の指定したインデックス位置にあるノードを取得します。

Public Overridable Function Item( _
   ByVal index As Integer _) As XmlNode
[C#]
public virtual XmlNode Item(intindex);
[C++]
public: virtual XmlNode* Item(intindex);
[JScript]
public function Item(
   index : int) : XmlNode;

パラメータ

  • index
    XmlNamedNodeMap から取得するノードのインデックス位置。インデックスは 0 から始まるため、最初のノードのインデックスは 0 で、最後のノードのインデックスは Count-1 になります。

戻り値

指定したインデックス位置にある XmlNode 。index が 0 未満か、 Count プロパティ以上の場合は、 null 参照 (Visual Basic では Nothing) が返されます。

使用例

[Visual Basic, C#, C++] XmlNamedNodeMap から継承される XmlAttributeCollection クラスを使用して、書籍のすべての属性を表示する例を次に示します。

 
Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book genre='novel' publicationdate='1997'> " & _
                "  <title>Pride And Prejudice</title>" & _
                "</book>")
                         
    Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes

    Console.WriteLine("Display all the attributes for this book...")
    Dim i As Integer
    For i = 0 To attrColl.Count - 1
       Console.WriteLine("{0} = {1}", attrColl.Item(i).Name,attrColl.Item(i).Value)
    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.LoadXml("<book genre='novel' publicationdate='1997'> " +
                 "  <title>Pride And Prejudice</title>" +
                 "</book>");      
 
     XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

     Console.WriteLine("Display all the attributes for this book...");
     for (int i=0; i < attrColl.Count; i++)
     {
        Console.WriteLine("{0} = {1}", attrColl.Item(i).Name, attrColl.Item(i).Value);
     }         
    
  }
}

[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->LoadXml(S"<book genre='novel' publicationdate='1997'>   <title>Pride And Prejudice</title></book>");      
 
     XmlAttributeCollection* attrColl = doc->DocumentElement->Attributes;

     Console::WriteLine(S"Display all the attributes for this book...");
     for (int i=0; i < attrColl->Count; i++)
     {
        Console::WriteLine(S"{0} = {1}", attrColl->Item(i)->Name, attrColl->Item(i)->Value);
     }         
}

[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 ファミリ, .NET Compact Framework - Windows CE .NET

参照

XmlNamedNodeMap クラス | XmlNamedNodeMap メンバ | System.Xml 名前空間