first_page

DonXML Responds to “Resolving XML Namespaces for XPath Procedures”

Don Demask, a.k.a. DonXML, was gracious enough to send me an email about my concerns in an earlier post. Here is an excerpt:

Parsing apart the XPath looking to see if it has prefixes isn’t something that I want to do, since this code is internal to the System.Xml.Xpath namespace. I’ve looked into the options that you listed below, and none feel right, so the only thing I can recommend is to deal with the fact that when you use XPath, you need to create an XmlNamespaceManager along with an XPath Query. In the XmlNamespaceManager you will load the prefix/namespace pairs used in your XPath statements. This way, you don’t have to do anything funky (a namespace can be loaded multiple times in a Manager and it will not throw an error). As long as you use the same prefixes that you loaded into the Manager in the XPath you are all good. If you are letting an end user to define the XPath and pass it into your code, you will need to let the user know about the prefix to namespace mapping that you are using to execute the query.

Don is working with the XML team in Redmond and one product to come out of this affair is something he calls “XPathMania,” a Visual Studio plugin. I’m sure he’ll have more on this later so watch his Blog.

rasx()