Freigeben über


XmlNodeList.Item-Methode

Ruft einen Knoten am angegebenen Index ab.

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

Syntax

'Declaration
Public MustOverride Function Item ( _
    index As Integer _
) As XmlNode
'Usage
Dim instance As XmlNodeList
Dim index As Integer
Dim returnValue As XmlNode

returnValue = instance.Item(index)
public abstract XmlNode Item (
    int index
)
public:
virtual XmlNode^ Item (
    int index
) abstract
public abstract XmlNode Item (
    int index
)
public abstract function Item (
    index : int
) : XmlNode

Parameter

  • index
    Nullbasierter Index für die Liste der Knoten.

Rückgabewert

Der XmlNode in der Auflistung. Wenn index größer oder gleich der Anzahl der Knoten in der Liste ist, wird NULL (Nothing in Visual Basic) zurückgegeben.

Beispiel

Im folgenden Beispiel wird der zweite Knoten in der XmlNodeList abgerufen und angezeigt.

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>" & _
                "</items>")
                         
     'Get and display the last item node.
     Dim root as XmlElement = doc.DocumentElement
     Dim nodeList as XmlNodeList = root.GetElementsByTagName("item")
     Console.WriteLine(nodeList.Item(1).InnerXml)
    
  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>" +
                 "</items>");
                         
     //Get and display the last item node.
     XmlElement root = doc.DocumentElement;
     XmlNodeList nodeList = root.GetElementsByTagName("item");
     Console.WriteLine(nodeList.Item(1).InnerXml);     
    
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<items>"
   "  <item>First item</item>"
   "  <item>Second item</item>"
   "</items>" );
   
   //Get and display the last item node.
   XmlElement^ root = doc->DocumentElement;
   XmlNodeList^ nodeList = root->GetElementsByTagName( "item" );
   Console::WriteLine( nodeList->Item( 1 )->InnerXml );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<items>"
            + "  <item>First item</item>"
            + "  <item>Second item</item>"
            + "</items>");

        //Get and display the last item node.
        XmlElement root = doc.get_DocumentElement();
        XmlNodeList nodeList = root.GetElementsByTagName("item");
        Console.WriteLine(nodeList.Item(1).get_InnerXml());
    } //main 
} //Sample

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlNodeList-Klasse
XmlNodeList-Member
System.Xml-Namespace