Resolving XML Namespaces for XPath Procedures
Namespace resolution is required when an XPath expression contains prefixes. There are about four ways to resolve namespaces in .NET:
- Get a prefix based on knowledge of its corresponding namespace URI. The
XPathNavigator.LookupPrefix()
method implements this. - Get a namespace URI based on knowledge of its corresponding prefix. The
XPathNavigator.LookupNamespace()
method implements this. - Get a namespace based on knowledge of the local name of the element. The
XPathNavigator.GetNamespace()
method implements this. - Get either prefix or URI based on knowledge of the nodal location of namespace declarations. The
XPathNavigator.GetNamespacesInScope()
method implements this. - Somehow disable namespace resolution in .NET.I wrote a static member for a helper class that returns an
XmlNamespaceManager
for this nodal location namespace resolution. Note that the XML types take advantage of new features in .NET 2.0, namely generics, to help solve this problem. Now I’m going to send this as email to DonXML to verify that this view is sound.
** Note: ** The code is not posted here due to the ‘security features’ in WordPress, my Blog software.