You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Alvaro Gonzalez <ag...@germinus.com> on 2006/03/13 13:08:04 UTC
Descendant-or-self
Hi list,
I have been doing some tests with "//" (descendant-or-self) axis, and i
think is not interpreted correctly by Jacrabbit Query Builder.
A query with this axis returns only "descendant" nodes instead of
"descendant-or-self" nodes. For example with this piece of code:
Node myTopNode =
rootNode.addNode("myTopNode");
myTopNode.addNode("subNode");
myTopNode.addNode("subNode");
rootNode.save();
String query = "//myTopNode//*";
//Should find all the 3 nodes: myTopNode and 2 subnodes.
QueryManager qm = currentSession.getWorkspace().getQueryManager();
Query q = qm.createQuery(query, Query.XPATH);
QueryResult qr = q.execute();
NodeIterator nodes = qr.getNodes();
assertEquals(3, nodes.getSize());
the test fails because it only finds two nodes instead of three. Is this
a bug? Am I misunderstanding "//" axis?
Regards,
Alvaro
--
Alvaro Gonzalez de Paz
Germinus XXI
http://www.germinus.com
Avda. de Manoteras, 44. 2ยช planta.
28050 - Madrid (Spain)
Tel (+34) 91 296 12 34
Fax (+34) 91 296 12 30
Re: Descendant-or-self
Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Alvaro,
as per XPath specification [1] your query will be expanded to:
/descendant-or-self::node()/myTopNode/descendant-or-self::node()/*
which will effectively match only descendant nodes of /myTopNode
what you are probably looking for is:
//myTopNode/descendant-or-self::node()
but this is currently not supported by jackrabbit because it is not
required by the JCR spec.
regards
marcel
[1] http://www.w3.org/TR/xpath20/#abbrev
Alvaro Gonzalez wrote:
> Hi list,
>
> I have been doing some tests with "//" (descendant-or-self) axis, and i
> think is not interpreted correctly by Jacrabbit Query Builder.
> A query with this axis returns only "descendant" nodes instead of
> "descendant-or-self" nodes. For example with this piece of code:
>
> Node myTopNode =
> rootNode.addNode("myTopNode");
> myTopNode.addNode("subNode");
> myTopNode.addNode("subNode"); rootNode.save();
> String query = "//myTopNode//*";
> //Should find all the 3 nodes: myTopNode and 2 subnodes.
> QueryManager qm = currentSession.getWorkspace().getQueryManager();
> Query q = qm.createQuery(query, Query.XPATH);
> QueryResult qr = q.execute();
> NodeIterator nodes = qr.getNodes();
> assertEquals(3, nodes.getSize());
>
> the test fails because it only finds two nodes instead of three. Is this
> a bug? Am I misunderstanding "//" axis?
>
> Regards,
>
> Alvaro
>