6

I have a XML document opened in Chrome and I would like to test some XPath expressions. The XML document involves different namespaces. How do I define the prefix URIs?

For testing XPath expressions in Chrome I have used $x("...") so far.

knb
  • 9,138
  • 4
  • 58
  • 85
Mahoni
  • 7,088
  • 17
  • 58
  • 115

2 Answers2

2

If you searched for an element "description" anywhere inside the XML document, you could use the local-name() function. Example:

$x("//*[local-name()='description']")

Inspired by this answer on SO.

Community
  • 1
  • 1
knb
  • 9,138
  • 4
  • 58
  • 85
1

as taken from developer.mozilla's Introduction_to_using_XPath_in_JavaScript

Implementing a User Defined Namespace Resolver

function nsResolver(prefix) {
  var ns = {
    'xhtml' : 'http://www.w3.org/1999/xhtml',
    'mathml': 'http://www.w3.org/1998/Math/MathML'
  };
  return ns[prefix] || null;
}
Wim Ombelets
  • 5,097
  • 3
  • 39
  • 55