jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Giota Karadimitriou" <Giota.Karadimitr...@eurodyn.com>
Subject RE: xpath failure
Date Tue, 14 Feb 2006 15:57:56 GMT
Hello,

I discovered that only if I use alphanumeric names for the node names I
can use xpath expressions of the form a/b//element(*,...).

If I use numbers as node names, even after escaping (e.g. nodes named
'1' or '2') my query returned 0 results.

When I used alphanumeric node names in the path, the xpath query worked.

Thanks.

Regards
Giota

-----Original Message-----
From: Giota Karadimitriou [mailto:Giota.Karadimitriou@eurodyn.com] 
Sent: Tuesday, February 14, 2006 11:29 AM
To: jackrabbit-dev@incubator.apache.org
Subject: RE: xpath failure

Thank you, like I said at the end of my email I already used the ISO9075

class, so it is nice to receive verification I'm on the right track
here;
however, when I used it to encode '/1/2' my program returns me 0 results
while it should have returned 1 (which is what happens when I run the
query without '/1/2' in front).

String pattern="/1/2";
            String patternNew=ISO9075.encode(pattern);
            System.out.println(patternNew);
            Query q =
qm.createQuery(patternNew+"//element(*,nt:resource)[jcr:contains(.,'aaaa
a')]", Query.XPATH);
QueryResult result = q.execute();
NodeIterator it = result.getNodes();
System.out.println("IT:"+it.getSize());
while (it.hasNext()) {
	Node n = it.nextNode();
	System.out.println("name:" + n.getName());
	System.out.println("path:" + n.getPath());
}
  

>_x002f_1_x002f_2

>IT:0


while in reality I should be getting

> IT:1
> name:100
> path:/1/2/99/100

which is what I get when I use just
"//element(*,nt:resource)[jcr:contains(.,'aaaaa')]" without "/1/2" in
front.

The jcr spec follows the same syntax in 6.6.3.4 when specifying
descendants so what could be wrong? I still get 0 results even if I put
/jcr:root/1/2 in front. Thank you.

Regards
Giota


-----Original Message-----
From: Marcel Reutegger [mailto:marcel.reutegger@gmx.net] 
Sent: Tuesday, February 14, 2006 10:47 AM
To: jackrabbit-dev@incubator.apache.org
Subject: Re: xpath failure

you need to encode the path steps because '1' and '2' is not a valid xml

name. xml names must not start with a digit.

you may use the utility org.apache.jackrabbit.util.ISO9075 to encode the

path steps. The class is included in the jackrabbit-commons.jar.

regards
  marcel

Giota Karadimitriou wrote:
> Hello,
>  
> the following xquery seems to fail with the below stack trace
>  
> QueryManager qm = session.getWorkspace().getQueryManager();
>             Query q =
>
qm.createQuery("/1/2//element(*,nt:resource)[jcr:contains(.,'aaaaa')]",
>                  Query.XPATH);
>  
>             QueryResult result = q.execute();
>             NodeIterator it = result.getNodes();
>              System.out.println("IT:"+it.getSize());
>             while (it.hasNext()) {
>                  Node n = it.nextNode();
>                 //System.out.println("UUID:" + n.getUUID());
>                 System.out.println("name:" + n.getName());
>                 System.out.println("path:" +
>                                    n.getPath());
>             }
>  
> javax.jcr.query.InvalidQueryException: Parse error: data is not a
> RelationQueryNode
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:435)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:462)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.childrenAccept(SimpleN
> ode.java:89)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.createPathQuery
> Node(XPathQueryBuilder.java:605)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQuer
> yBuilder.java:318)
>             at
>
org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.j
> ava:80)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.<init>(XPathQue
> ryBuilder.java:245)
>             at
>
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.createQuery(XPa
> thQueryBuilder.java:276)
>             at
>
org.apache.jackrabbit.core.query.xpath.QueryBuilder.createQueryTree(Quer
> yBuilder.java:37)
>             at
>
org.apache.jackrabbit.core.query.QueryParser.parse(QueryParser.java:54)
>             at
>
org.apache.jackrabbit.core.query.lucene.QueryImpl.<init>(QueryImpl.java:
> 125)
>             at
>
org.apache.jackrabbit.core.query.lucene.SearchIndex.createExecutableQuer
> y(SearchIndex.java:283)
>             at
> org.apache.jackrabbit.core.query.QueryImpl.init(QueryImpl.java:93)
>             at
>
org.apache.jackrabbit.core.SearchManager.createQuery(SearchManager.java:
> 185)
>             at
>
org.apache.jackrabbit.core.query.QueryManagerImpl.createQuery(QueryManag
> erImpl.java:87)
>             at com.ed.m2.test.TestJSR.main(TestJSR.java:297)
>  
>  
> If I remove */1/2* things seem to work ok
>  
> QueryManager qm = session.getWorkspace().getQueryManager();
>             Query q =
> qm.createQuery("//element(*,nt:resource)[jcr:contains(.,'aaaaa')]",
>                  Query.XPATH);
>  
>             QueryResult result = q.execute();
>             NodeIterator it = result.getNodes();
>              System.out.println("IT:"+it.getSize());
>             while (it.hasNext()) {
>                  Node n = it.nextNode();
>                 //System.out.println("UUID:" + n.getUUID());
>                 System.out.println("name:" + n.getName());
>                 System.out.println("path:" +
>                                    n.getPath());
>             }
>  
> IT:1
> name:100
> path:/1/2/99/100
>  
> I took a look at the forums and found out that it could be an escape
> name problem; however this does not seem to be the case
> since I have a very simple path /1/2 without spaces or special
> characters. If I run ISO9075.encode on *1/2* it does not fail  but
does
> not provide the result either.
> If I encode */1/2* it fails.
>  
> String pattern="1/2";
>             String patternNew=ISO9075.encode(pattern);
>             System.out.println(patternNew);
>             Query q =
>
qm.createQuery("/"+patternNew+"//element(*,ed:resource)[jcr:contains(.,'
> aaaaa')]",
>                  Query.XPATH);
>  
> Has anybody else run across such a problem?
>  
> I also tried putting /jcr:root in front but had the same results.
> 




Mime
View raw message