Export (0) Print
Expand All

XmlNamedNodeMap.Item Method

Retrieves the node at the specified index in the XmlNamedNodeMap.

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

Parameters

index
The index position of the node to retrieve from the XmlNamedNodeMap. The index is zero-based; therefore, the index of the first node is 0 and the index of the last node is Count-1.

Return Value

The XmlNode at the specified index. If index is less than 0 or greater than or equal to the Count property, a null reference (Nothing in Visual Basic) is returned.

Example

[Visual Basic, C#, C++] The following example uses the XmlAttributeCollection class (which inherits from XmlNamedNodeMap) to display all the attributes of a book.

[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlNamedNodeMap Class | XmlNamedNodeMap Members | System.Xml Namespace

Show:
© 2015 Microsoft