jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Weighill-Smith <phil.weighill-sm...@volantis.com>
Subject Re: Select all leafs of a tree w/XPath
Date Sat, 08 Nov 2008 22:25:51 GMT
Are you sure you can't use the XPath expression:

//*[count(child::*) = 0]

to select the element nodes that have no children (i.e. leaf nodes)?

Phil :n.

----- "Jukka Zitting" <jukka.zitting@gmail.com> wrote:

> Hi,
> 
> On Sat, Nov 8, 2008 at 6:53 PM, Sergey Podatelev
> <brightnesslevels@gmail.com> wrote:
> > Seriously, guys, is there an easy way to select leafs or I have to
> implement
> > a particular property for this?
> 
> There is no query constraint for selecting leaf nodes.
> 
> Your idea of using a particular property that you only set on leaf
> nodes is one way to do this. An alternative would be to use normal
> tree traversal like this:
> 
>     void visitLeaves(Node node) {
>         NodeIterator nodes = node.getNodes();
>         if (!nodes.hasNext()) {
>             // ... this is a leaf node, process it ...
>         } else {
>             while (nodes.hasNext()) {
>                 visitLeaves(nodes.nextNode());
>             }
>         }
>     }
> 
> BR,
> 
> Jukka Zitting

Mime
View raw message