1

I have firexpath, and it doesn't seem to be working with xpath. Even something simple //div returns no results. Even if I click on an existing node, say "copy XPath" and then paste that XPath into filter input box, it says "no nodes found". //*[name()='div'] does work though. Am I missing a namespace or something? Here is what root tag looks like (it's a valid XHTML):

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" class="ff ff3">

I didn't find a support forum for FireXPath, so I'm posting it here.

THX-1138
  • 21,316
  • 26
  • 96
  • 160
  • Good question, +1. See my answer for explanation and for three alternative solutions. :) – Dimitre Novatchev Mar 13 '11 at 02:24
  • One of many possible duplicate of [XPath is returning null for xml with defaultNamespace](http://stackoverflow.com/questions/4380006/xpath-is-returning-null-for-xml-with-defaultnamespace) –  Mar 13 '11 at 21:04
  • Reference specifically to firepath makes it unique as namespace registration in firepath seems non existant. – rogermushroom Mar 14 '11 at 14:58

2 Answers2

0

I have not used firexpath but it looks as though the default namespace xmlns="http://www.w3.org/1999/xhtml" is preventing xpath from finding the div as the div element inside the element which defies xmlns with be prefixed with that namespace.

You therefore would need to register the namespace with firexpath using some sort of method call??? then //div should work or your expression is fine as well, if you were wanting to consider namespaces in the expression you could include a check for the namespace like so

//*[name()='div' and namespace-uri()='http://www.w3.org/1999/xhtml']

EDIT:

I have downloaded firexpath which now is called firepath and it doesn't look possible to register a namespace so it looks like you will have to the name() method

rogermushroom
  • 5,486
  • 4
  • 42
  • 68
0

In case you cannot register a namespace (for the default namespace) and then prefix every element name in the XPath expression with the registered prefix, then you can use an XPath expression like this:

 /*[name()='x']/*[name()='y']/*[name()='z']

In case there are elements belonging to other namespaces (than the default namespace), you'll have to use a more specific XPath expression:

 /*[name()='x' and namespace-uri()='http://www.w3.org/1999/xhtml']
      /*[name()='y' and namespace-uri()='http://www.w3.org/1999/xhtml']
          /*[name()='z' and namespace-uri()='http://www.w3.org/1999/xhtml']

If you could have registered the default namespace and the prefix was (say) "p", then the above would be equivalent to a now simpler expression:

/p:x/p:y/p:z
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431