XPathExpression::AddSort Method (Object^, IComparer^)
When overridden in a derived class, sorts the nodes selected by the XPath expression according to the specified IComparer object.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- expr
-
Type:
System::Object^
An object representing the sort key. This can be the string value of the node or an XPathExpression object with a compiled XPath expression.
- comparer
-
Type:
System.Collections::IComparer^
An IComparer object that provides the specific data type comparisons for comparing two objects for equivalence.
| Exception | Condition |
|---|---|
| XPathException | The XPathExpression or sort key includes a prefix and either an XmlNamespaceManager is not provided, or the prefix cannot be found in the supplied XmlNamespaceManager. |
The AddSort method enables users to sort objects by their data type instead of by string or number. The IComparer object provides an implementation of the Compare method that supports sorting on user-defined classes.
In the following example, the books are sorted by ISBN number, where isbn is an object that implements the IComparer interface.
The following are important notes to consider when using the AddSort method.
The order in which the sorts are added provides the sort key order.
If the XPathExpression or the sort key requires namespace resolution, you must use the SetContext method to provide an XmlNamespaceManager for namespace resolution.
If the XPathExpression does not include a prefix, it is assumed that the namespace Uniform Resource Identifier (URI) is the empty namespace. If your XML includes a default namespace, you must still use the SetContext method and provide an XmlNamespaceManager that contains a prefix and namespace URI to handle the default namespace.
Available since 1.1
Silverlight
Available since 4.0