You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Shane O'Sullivan <sh...@gmail.com> on 2006/07/26 18:43:04 UTC

How to select nodes that do NOT have a given child in JackRabbit

I need to be able to run an XPATH query on jackrabbit that will allow me to
select all nodes that do not have a particular child.

For example, given the tree

<A>
    <B>
</A>
<A>
    <C>
</A>

I want to only select the "A" nodes that don't have a <B> child.
With Xpath I should be able to do something like
    /A/*[name()!='B']
or
    /A/*[count(B)=0]

but JackRabbit says that both of these XPath functions are not supported.
Does anyone know of another way to do this?

Thanks,

Shane

Re: How to select nodes that do NOT have a given child in JackRabbit

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 7/26/06, Shane O'Sullivan <sh...@gmail.com> wrote:
> I need to be able to run an XPATH query on jackrabbit that will allow me to
> select all nodes that do not have a particular child.

You'd need the child axis support as requested in JCR-247 to do that
with XPath. It's not required by the JSR-170 nor supported by
Jackrabbit, so the only way to achieve something like that is with a
workaround. Some ideas:

* Use an explicit property to flag the presence or absence of the
child nodes you're interested. Whenever you add or remove such child
nodes, you also update the flag property. You can use observation to
trigger the update to avoid mixing this workaround with normal code.

* Use a partial XPath query (get all "A" nodes) and filter the results
with Node.hasNode("B").

* Vote for JSR-247 or contribute a patch that adds this functionality.
This is likely quite hard, as the current Jackrabbit query index isn't
really optimized for such access.

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development