When overridden in a derived class, specifies the System.Xml.IXmlNamespaceResolver object to use for namespace resolution.
- nsResolver
- An object that implements the System.Xml.IXmlNamespaceResolver interface to use for namespace resolution.
Namespace resolution is supported using classes that implement the System.Xml.IXmlNamespaceResolver interface, such as the System.Xml.XmlNamespaceManager class. The System.Xml.XmlNamespaceManager stores prefix and namespace Uniform Resource Identifier (URI) mappings. If the System.Xml.XPath.XPathExpression requires namespace resolution, the prefix and namespace URI pair must be added to an object, such as the System.Xml.XmlNamespaceManager class, which implements the System.Xml.IXmlNamespaceResolver interface, and the XPathExpression.SetContext(System.Xml.IXmlNamespaceResolver) method must be called to specify the System.Xml.IXmlNamespaceResolver interface object to use for namespace resolution.
The following are important notes to consider when using the XPathExpression.SetContext(System.Xml.IXmlNamespaceResolver) method.
If the System.Xml.XPath.XPathExpression does not include a prefix, it is assumed that the namespace URI is the empty namespace. If your XML includes a default namespace, you must still use the XPathExpression.SetContext(System.Xml.IXmlNamespaceResolver) method and provide an object that contains a prefix and namespace URI to handle the default namespace.
You can also supply an System.Xml.IXmlNamespaceResolver interface object for namespace resolution to the XPathExpression.Compile(string, System.Xml.IXmlNamespaceResolver) method when you create your System.Xml.XPath.XPathExpression object.
XPathExpression.SetContext(System.Xml.IXmlNamespaceResolver) accepts System.Xml.Xsl.XsltContext as a namespace resolver, so you can implement a custom context and use functions and variables based on System.Xml.Xsl.IXsltContextFunction and System.Xml.Xsl.IXsltContextVariable. The XPath expression will execute them. For more information, see User Defined Functions and Variables.