XmlNodeList.ItemOf[Int32] Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a node at the given index.
public:
virtual property System::Xml::XmlNode ^ default[int] { System::Xml::XmlNode ^ get(int i); };
public virtual System.Xml.XmlNode this[int i] { get; }
public virtual System.Xml.XmlNode? this[int i] { get; }
member this.ItemOf(int) : System.Xml.XmlNode
Default Public Overridable ReadOnly Property ItemOf(i As Integer) As XmlNode
Parameters
- i
- Int32
The zero-based index into the list of nodes.
Property Value
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
.
Examples
The following example creates an XmlDocument object and uses the GetElementsByTagName method and the resulting XmlNodeList
to display all the book titles.
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew 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 );
}
}
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);
}
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.Load("2books.xml")
' Get and display all the book titles.
Dim root as XmlElement = doc.DocumentElement
Dim elemList as XmlNodeList = root.GetElementsByTagName("title")
Dim i as integer
for i=0 to elemList.Count-1
Console.WriteLine(elemList.ItemOf(i).InnerXml)
next
end sub
end class
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>
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기