[jdom-interest] Element versus Document with XPath
Jason Hunter
jhunter at xquery.com
Wed Nov 9 10:34:48 PST 2005
Your XPath probably includes the name of the element against which you
were trying to execute the XPath. That works OK if you're starting at a
document node (because that elt is its first child), but not if you're
at the element itself.
Say you have:
<a>
<b/>
</a>
If you start your XPath at the document, then "a/b" returns "b". If you
start at "a", you'll get nothing because "a" has no child named "a"
which is what "a/b" would be asking for.
-jh-
Mark Hale wrote:
> I was wondering if any of you have ever experienced the same problems.
> If I do an :
>
> Element result = (Element) XPath.selectSingleNode(el, "some
> path");
>
> I get result=null. However, if I do:
>
> Document doc = new Document ((Element) el.clone(), new
> DocType("xml"));
> Element result = (Element) XPath.selectSingleNode(doc, "some
> path");
>
> I get the right answer for result.
>
> Why is it that Xpath doesn't work on the element but does on the
> document?
>
> Thanks - I am stumped and see this behaviour quite often.
>
> Mark
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
More information about the jdom-interest
mailing list