XmlNodeList.Item(Int32) 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索给定索引处的节点。
public:
abstract System::Xml::XmlNode ^ Item(int index);
C#
public abstract System.Xml.XmlNode Item (int index);
C#
public abstract System.Xml.XmlNode? Item (int index);
abstract member Item : int -> System.Xml.XmlNode
Public MustOverride Function Item (index As Integer) As XmlNode
- index
- Int32
节点列表中从零开始的索引。
XmlNode 与集合中的指定索引. 如果 index
大于或等于列表中的节点数,则这返回 null
。
以下示例获取并显示第二个节点。XmlNodeList
#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 );
}
C#
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);
}
}
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
产品 | 版本 |
---|---|
.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 |
.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 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |