XPathNavigator.ComparePosition(XPathNavigator) 方法

定义

将当前 XPathNavigator 的位置与指定的 XPathNavigator 的位置进行比较。Compares the position of the current XPathNavigator with the position of the XPathNavigator specified.

public:
 virtual System::Xml::XmlNodeOrder ComparePosition(System::Xml::XPath::XPathNavigator ^ nav);
public virtual System.Xml.XmlNodeOrder ComparePosition (System.Xml.XPath.XPathNavigator nav);
abstract member ComparePosition : System.Xml.XPath.XPathNavigator -> System.Xml.XmlNodeOrder
override this.ComparePosition : System.Xml.XPath.XPathNavigator -> System.Xml.XmlNodeOrder
Public Overridable Function ComparePosition (nav As XPathNavigator) As XmlNodeOrder

参数

nav
XPathNavigator

要针对其进行比较的 XPathNavigatorThe XPathNavigator to compare against.

返回

XmlNodeOrder

XmlNodeOrder 值,表示两个 XPathNavigator 对象的相对位置。An XmlNodeOrder value representing the comparative position of the two XPathNavigator objects.

注解

下表对枚举进行了说明 XmlNodeOrderThe following table describes the XmlNodeOrder enumeration.

XmlNodeOrderXmlNodeOrder 描述Description
Before 此的当前节点 XPathNavigator 位于所提供的的当前节点之前 XPathNavigatorThe current node of this XPathNavigator is before the current node of the supplied XPathNavigator.
After 此的当前节点 XPathNavigator 位于所提供的的当前节点之后 XPathNavigatorThe current node of this XPathNavigator is after the current node of the supplied XPathNavigator.
Same 这两个 XPathNavigator 对象位于同一节点上。The two XPathNavigator objects are positioned on the same node.
Unknown 不能以文档顺序相对于彼此来确定节点位置,也不能将其 null 指定为 XPathNavigator 参数。The node positions cannot be determined relative to each other in the document order, or null is specified as the XPathNavigator parameter. 如果两个节点驻留在不同的树中,则可能发生这种情况。This could occur if the two nodes reside in different trees.

ComparePosition 方法的行为取决于当前所 XPathNodeType XPathNavigator 处的。The ComparePosition method's behavior is dependent on the XPathNodeType the XPathNavigator is currently positioned on. 在比较 XML 文档中的节点时,下列规则适用:When comparing nodes in the XML document, the following rules apply:

  • Element 节点:这些节点按文档顺序从源文档返回。Element nodes: These nodes are returned in document order from the source document.

  • Namespace 节点:这些节点可以按文档顺序返回,并且始终位于 Attribute 父元素的节点之前。Namespace nodes: These nodes may be returned in document order and are always before the Attribute nodes of the parent element.

  • Attribute 节点:可以按文档顺序返回这些节点。Attribute nodes: These nodes may be returned in document order. 它们始终位于 Namespace 父节点的节点和子节点之前。They always come after the Namespace nodes and before any child nodes of the parent node.

备注

有关 XPath 数据模型的详细信息以及每个节点类型的详细信息,请参阅 W3C XML 路径语言的第5节 (XPath) 建议。For more information about the XPath data model and details about each of the node types, see section 5 of the W3C XML Path Language (XPath) recommendation.

此方法对的状态没有影响 XPathNavigatorThis method has no effect on the state of the XPathNavigator.

备注

如果可能,请使用 IsSamePosition 方法而不是 ComparePosition 方法。Use the IsSamePosition method rather than the ComparePosition method when possible.

适用于

另请参阅