Llegeix en anglès

Comparteix a través de


XmlNodeList.ItemOf[Int32] Propiedad

Definición

Obtiene un nodo en el índice especificado.

public virtual System.Xml.XmlNode this[int i] { get; }
public virtual System.Xml.XmlNode? this[int i] { get; }

Parámetros

i
Int32

Índice de base cero en la lista de nodos.

Valor de propiedad

XmlNode con el índice especificad en la colección. Si el índice es mayor o igual que el número de nodos de la lista, esto devuelve null.

Ejemplos

En el ejemplo siguiente se crea un XmlDocument objeto y se usa el GetElementsByTagName método y el resultado XmlNodeList para mostrar todos los títulos del libro.

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

En el ejemplo se usa el archivo 2books.xml como entrada.

<!--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>

Se aplica a

Producte Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0