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
  • 8,852
  • 4
  • 55
  • 80
Mahoni
  • 6,598
  • 13
  • 52
  • 108

2 Answers2

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
  • 4,725
  • 3
  • 39
  • 51
1

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
  • 8,852
  • 4
  • 55
  • 80