XPathNodeIterator 类

在一组选中的节点上提供迭代器。

**命名空间:**System.Xml.XPath
**程序集:**System.Xml(在 system.xml.dll 中)

语法

声明
Public MustInherit Class XPathNodeIterator
    Implements ICloneable, IEnumerable
用法
Dim instance As XPathNodeIterator
public abstract class XPathNodeIterator : ICloneable, IEnumerable
public ref class XPathNodeIterator abstract : ICloneable, IEnumerable
public abstract class XPathNodeIterator implements ICloneable, IEnumerable
public abstract class XPathNodeIterator implements ICloneable, IEnumerable

备注

XPathNavigator 类返回的 XPathNodeIterator 对象不是位于所选节点集的第一个节点上。必须调用 XPathNodeIterator 类的 MoveNext 方法,以将 XPathNodeIterator 对象定位到所选节点集的第一个节点上。

给继承者的说明 当从 XPathNodeIterator 类继承时,必须重写以下成员:

示例

下面的示例使用 XPathNavigator 类的 Select 方法以及 XPathNodeIterator 类来选择节点集。

Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim nodes As XPathNodeIterator = navigator.Select("/bookstore/book")
Dim nodesNavigator As XPathNavigator = nodes.Current

Dim nodesText As XPathNodeIterator = nodesNavigator.SelectDescendants(XPathNodeType.Text, False)

While nodesText.MoveNext()
    Console.Write(nodesText.Current.Name)
    Console.WriteLine(nodesText.Current.Value)
End While
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathNodeIterator nodes = navigator.Select("/bookstore/book");
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);

while (nodesText.MoveNext())
{
    Console.Write(nodesText.Current.Name);
    Console.WriteLine(nodesText.Current.Value);
}

该示例使用 books.xml 文件作为输入。

<bookstore>
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

继承层次结构

System.Object
  System.Xml.XPath.XPathNodeIterator

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

XPathNodeIterator 成员
System.Xml.XPath 命名空间