Export (0) Print
Expand All

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

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft