You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Joan Xiao <jx...@polivec.com> on 2006/01/27 20:00:13 UTC
Query by node name
Hello,
I'm having some problem when I try to query the repository by node name.
I have a custom node type, say my:file, which extends nt:file. And I'm
able to add nodes of this custom node type and then retrieve them
successfully.
Now I need to determine whether a node of certain name exists in the
repository. If I use the query string: //element(*, my:file), it
correctly returns all nodes of the type my:file. So suppose I have a
node of this type with path /Documents/test.txt, it does get returned.
But if I replace * by a node name, i.e., //element(test.txt, my:file),
it doesn't return anything even though the file exists and is returned
from the previous query.
I've also tried the following queries:
/Documents//element(*, my.file): returns nothing
/Documents//element(test.txt, my.file): returns nothing
/jcr:root//element(*, my.file): returns nothing
/jcr:root/Documents//element(*, my.file): returns nothing
/jcr:root/Documents//element(test.txt, my.file): returns nothing
I've also tried to use SQL query, but the result is consistent with
XPATH.
Is there anything I'm doing wrong here?
Thanks for any help.
Joan
Re: Query by node name
Posted by Marcel Reutegger <ma...@gmx.net>.
Joan Xiao wrote:
> But if I replace * by a node name, i.e., //element(test.txt, my:file),
> it doesn't return anything even though the file exists and is returned
> from the previous query.
I'm not able to reproduce this. could you please file a jira issue on
http://issues.apache.org/jira/browse/JCR and provide a code fragment
that reproduces the problem you described?
> I've also tried the following queries:
> /Documents//element(*, my.file): returns nothing
> /Documents//element(test.txt, my.file): returns nothing
> /jcr:root//element(*, my.file): returns nothing
> /jcr:root/Documents//element(*, my.file): returns nothing
> /jcr:root/Documents//element(test.txt, my.file): returns nothing
there are two issues with the above queries:
1) /Documents will never return any nodes because absolute XPath queries
must always begin with /jcr:root (see spec section 6.6.4.3 for details)
you may also use a relative path:
Documents//elements(*, my:file)
2) my.file ? I guess this should be my:file. Unless you have a node type
without a namespace prefix and a local name 'my.file' this will of
course never match.
regards
marcel