[jdom-interest] XPATH Question

Stefan Schoenmackers stef at cparity.com
Thu May 8 15:09:04 PDT 2003


What about trying something along the lines of:

/.../parent-tag[category[@level=certain_level]="certain string"]

I tried the parent-tag part on the following document:

(modified xpath: /root/parent-tag[category[@level=1]="A"]  )

<root>
<parent-tag>
    <category level="1">A</category>
    <category level="2">B</category>
    <category level="3">C</category>
</parent-tag>
<parent-tag>
    <category level="3">H</category>
    <category level="4">I</category>
    <category level="5">A</category>
</parent-tag>
</root>

The original way returned two nodes, whereas the xpath above only returned
one (the top one).  The problem with your xpath, to the best of my
knowledge (I am by no means an expert), is that the boolean and argument
intersects the matching node-sets after evaluating each piece.  I.e.
running your xpath intersected the set of all parent-tag's that had a
category matching "certain string" with the set of all parent-tag's having
a category child with @level=some_level .  If you add the level clause to
category child as above, then it will only match category nodes at the
specified level first, and then those that match the given string (or
maybe in the other order, but it will have the same effect). 

Hopefully that makes sense.

--Stef Sch...

On Thu, 8 May 2003, Sanjeev Verma [CONTRACTOR] wrote:

> Hi all:
> 
> Although I am using JDom in my application, this is purely an XPath question.
> 
> I have an XML document, that has a "*" as the multiplicity assigned to an 
> element. This element, lets say category, is defined to have a PCDATA value and 
> an attribute called "level", which can be 1, 2, 3...
> 
> My problem is, I need an XPath expression by which I can select parent node of 
> all such category elements whose PCDATA value equals "certain string" and whose 
> attribute "level" equals "certain level". I used an expression like:
> 
> /.../parent-tag[category="certain string" and category[@level=certain_level]]
> 
> But this expression gives erroneous output, because of the multiplicity of this 
> element. What I get is a list of <parent-tag> where ANY category element has 
> PCDATA equals "certain string" and ANY OTHER category element attribute level 
> equals "certain level". That is, it is not the same category element that is 
> being used for comparison.
> 
> Is the problem statement clear? can someone help?
> 
> Best Regards
> 
> Sanjeev
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 




More information about the jdom-interest mailing list