Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ComparePosition Method

XPathNavigator.ComparePosition Method

Compares the position of the current XPathNavigator with the position of the XPathNavigator specified.

Namespace:  System.Xml.XPath
Assembly:  System.Xml (in System.Xml.dll)

abstract ComparePosition : 
        nav:XPathNavigator -> XmlNodeOrder  
override ComparePosition : 
        nav:XPathNavigator -> XmlNodeOrder


Type: System.Xml.XPath.XPathNavigator

The XPathNavigator to compare against.

Return Value

Type: System.Xml.XmlNodeOrder
An XmlNodeOrder value representing the comparative position of the two XPathNavigator objects.

The following table describes the XmlNodeOrder enumeration.




The current node of this XPathNavigator is before the current node of the supplied XPathNavigator.


The current node of this XPathNavigator is after the current node of the supplied XPathNavigator.


The two XPathNavigator objects are positioned on the same node.


The node positions cannot be determined relative to each other in the document order, or a null reference (Nothing in Visual Basic) is specified as the XPathNavigator parameter. This could occur if the two nodes reside in different trees.

The ComparePosition method's behavior is dependent on the XPathNodeType the XPathNavigator is currently positioned on. When comparing nodes in the XML document, the following rules apply:

  • Element nodes: These nodes are returned in document order from the source document.

  • Namespace nodes: These nodes may be returned in document order and are always before the Attribute nodes of the parent element.

  • Attribute nodes: These nodes may be returned in document order. They always come after the Namespace nodes and before any child nodes of the parent node.


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 located at http://www.w3.org/TR/xpath#data-model.

This method has no effect on the state of the XPathNavigator.


Use the IsSamePosition method rather than the ComparePosition method when possible.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft