This documentation is archived and is not being maintained.

XmlNamedNodeMap.Item Method

Retrieves the node at the specified index in the XmlNamedNodeMap.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

public virtual XmlNode Item (
	int index
)
public XmlNode Item (
	int index
)
public function Item (
	index : int
) : XmlNode
Not applicable.

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.

The following example uses the XmlAttributeCollection class (which inherits from XmlNamedNodeMap) to display all the attributes of a book.

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);
     }         
    
  }
}

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book genre='novel' publicationdate='1997'> "
            + "  <title>Pride And Prejudice</title>"
            + "</book>");

        XmlAttributeCollection attrColl = 
            doc.get_DocumentElement().get_Attributes();

        Console.WriteLine("Display all the attributes for this book...");
        for (int i = 0; i < attrColl.get_Count(); i++) {
            Console.WriteLine("{0} = {1}", attrColl.Item(i).get_Name(), 
                attrColl.Item(i).get_Value());
        }
    } //main 
} //Sample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: