This documentation is archived and is not being maintained.

XmlNodeList.Item Method

Retrieves a node at the given index.

[Visual Basic]
Public MustOverride Function Item( _
   ByVal index As Integer _
) As XmlNode
public abstract XmlNode Item(
 int index
public: virtual XmlNode* Item(
 int index
) = 0;
public abstract function Item(
   index : int
) : XmlNode;


Zero-based index into the list of nodes.

Return Value

The XmlNode in the collection. If index is greater than or equal to the number of nodes in the list, this returns a null reference (Nothing in Visual Basic).


[Visual Basic, C#, C++] The following example gets and displays the second node in the XmlNodeList.

[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("<items>" & _
                "  <item>First item</item>" & _
                "  <item>Second item</item>" & _
     'Get and display the last item node.
     Dim root as XmlElement = doc.DocumentElement
     Dim nodeList as XmlNodeList = root.GetElementsByTagName("item")
  end sub
end class

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {
     XmlDocument doc = new XmlDocument();
     doc.LoadXml("<items>" +
                 "  <item>First item</item>" +
                 "  <item>Second item</item>" +
     //Get and display the last item node.
     XmlElement root = doc.DocumentElement;
     XmlNodeList nodeList = root.GetElementsByTagName("item");

#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
     XmlDocument* doc = new XmlDocument();
                  S"  <item>First item</item>" 
                  S"  <item>Second item</item>" 
     //Get and display the last item node.
     XmlElement* root = doc->DocumentElement;
     XmlNodeList* nodeList = root->GetElementsByTagName(S"item");

[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.


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

XmlNodeList Class | XmlNodeList Members | System.Xml Namespace