jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: xpath failure
Date Tue, 14 Feb 2006 08:47:21 GMT
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