Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

XmlNodeList.ItemOf Property

Gets a node at the given index.

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

public virtual XmlNode this[
	int i
] { get; }

Parameters

i
Type: System.Int32

The zero-based index into the list of nodes.

Property Value

Type: System.Xml.XmlNode
The XmlNode with the specified index in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

The following example creates an XmlDocument object and uses the GetElementsByTagName method and the resulting XmlNodeList to display all the book titles.

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

public class Sample
{
  public static void Main()
  {
     XmlDocument doc = new XmlDocument();
     doc.Load("2books.xml");

     // Get and display all the book titles.
     XmlElement root = doc.DocumentElement;
     XmlNodeList elemList = root.GetElementsByTagName("title");
     for (int i=0; i < elemList.Count; i++)
     {   
        Console.WriteLine(elemList[i].InnerXml);
     } 

  }
}

The example uses the file 2books.xml as input.

<!--sample XML fragment-->
<bookstore>
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
    <price>19.95</price>
  </book>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>
    <price>24.95</price>
  </book>
</bookstore>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft