|
Hi Steen
You've just found a quirk in the current XPath
support which is going away in the next release.
Incidentally the "expression context" is the XPath
expression itself, rather than the part of the tree thats being navigated when
the expression is evaluated.
What I tried to do was add what I thought was a
sensible defaulting mechanism to dom4j so that if you knew what prefixes were
used in the document, you could also use them in the XPath expression. However
the implementation was a little quirky (as your example shows) as it used the
current node on which the XPath is being evaluated rather than the initial
context node.
I was planning to fix this, so that if no prefixes
are explicitly mapped then all the prefixes avaiable on the initial context (the
root <z:A> element in your example) would be used by default.
There's been some debate recently on the Jaxen list
as to whether this behaviour actually confuses people more than it helps them.
The argument being that it makes people think that the prefixes used in the
XPath expression are related to the prefixes used in the document - which isn't
true -they are totally independent, all that matters is the URIs they map
to.
I'm swaying towards this position right now as most
of the time we shouldn't guess, up front, what the namespace prefixes were used
in a document but rather should set them up explicitly to point to the URIs we
wish to compare against.
Incidentaly, the quick way to fix your example is
to dodge the prefix-issue completely and do
//*[namespace-uri()='urn:zorglub']
James
|
Title: RE: [dom4j-user] simplest way to use namespaces URI in xpath in dom4j?
- [dom4j-user] simplest way to use namespaces U... Martijn Koster
- RE: [dom4j-user] simplest way to use nam... Steen Lehmann - SilverStream
- Re: [dom4j-user] simplest way to use nam... James Strachan
- RE: [dom4j-user] simplest way to use nam... Steen Lehmann - SilverStream
- James Strachan
