Mahoni
Mahoni

Reputation: 7466

Test XPath expressions with namespaces in Chrome

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.

Upvotes: 7

Views: 1195

Answers (2)

knb
knb

Reputation: 9295

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.

Upvotes: 3

Wim Ombelets
Wim Ombelets

Reputation: 5265

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;
}

Upvotes: 2

Related Questions