Ignoring XPath Namespaces
08 December 2010
XML namespaces might be useful for resolving conflicts when combining segments from multiple XML entitied into a single file. They can also be extremely useful for versioning large complicated documents. But, to most developers who are merely trying to accomplish simple tasks in a short amount of time, they are nothing more than obstacles.
It is still common to see code that uses XmlNamespaceManager syntax when trying to adjust for namespaces. I have always felt that this syntax was overkill and overly complicated for everyday situations. It is also hard to remember, so there is a lot of copy-and-paste inheritance. Worst of all, it does not work for nearly identical documents that do not include the namespace.
A simpler way of handling this problem is to modify the syntax of the XPaths themselves. For example, the following code accomplishes the same return for documents containing namespaces, but it still works on similar xml where the namespaces are excluded. I also feel that it is much easier to remember.
is licensed under a Creative Commons Attribution 4.0 International License