Phillip Rhodes | 1 May 2007 21:34
Favicon

// in xpath does not match immediate children

Hello everyone,

I am using jackrabbit to store "tags" that a user creates. 
Given a structure (below) where each leaf node has an attribute of CONTENT_TYPE with a value of "Tag"
/myfolder/tag 1/Tag 1
/myfolder/tag 2/Tag 2
/myfolder/tag 3/Tag 3

My application needs to be able to query for what tags exist under a node path 
e.g. 
what tags are under /myfolder/tag 1?
what tags are usder /myfolder/?

My problem is that my xpath expression is not working for queries that pass the tag parent in as a node to look down.
I have a tag with a node path of /myfolder/tag 1/Tag 1 , but xpath search for tags in /myfolder/tag 1 fails to
find any nodes.

This query will not find it:
/jcr:root/myfolder/tag 1//*[ <at> CONTENT_TYPE = 'Tag']

This query does find it (but it is not restrictive enough, returns nodes in all folders).
/jcr:root/myfolder//*[ <at> CONTENT_TYPE = 'Tag']
Results
/myfolder/tag 1/Tag 1
/myfolder/tag 2/Tag 2
/myfolder/tag 3/Tag 3
/myfolder/tag 4/Tag 4

Is there a way to do a search in xpath that does children AND it's descendents?

(Continue reading)

Amir Mistric | 2 May 2007 01:32

Xpath query with number

Hi all


I am trying to pull some data from Magnolia's Jackrabbit repository and am having a difficulty with the
following Xpath query.


/jcr:root/www-site1-org/mediaroom/press/2006//element(*,nt:base)[ <at> tag='news' and
MetaData/ <at> mgnl:template='np-article'] order by  <at> date descending


The error I get is


javax.jcr.query.InvalidQueryException: Parse error: data is not a RelationQueryNode
        at org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQueryBuilder.java:448)
        at org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.java:80)
...



The weird thing is that if I omit '2006' from the above query it works...
So, I guess is there a special way of 'encoding' the number in Xpath query or do I need to do something else... 


Thanks

Amir
Amir Mistric | 2 May 2007 02:41

RE: Xpath query with number

Hmm

According to this issue (http://issues.apache.org/jira/browse/JCR-579) , Id be better off to use SQL syntax.
But now I have a different problem...How do I achieve the same result in SQL? I haven't been able to query
MetaData part..

In another words this does not work:

SELECT * FROM nt:base WHERE jcr:path LIKE '/www-site1-org/mediaroom/press/2006[%]/%' AND tag='news'
AND mgnl:template='np-article'


I am guessing because 'tag' and 'mgnl:template' are not on the same "level"....
Any help is appreciated...




Thanks
 
Amir

-----Original Message-----
From: Amir Mistric [mailto:amistric <at> nemours.org] 
Sent: Tuesday, May 01, 2007 7:33 PM
To: users <at> jackrabbit.apache.org
Subject: Xpath query with number

Hi all

(Continue reading)

Amir Mistric | 2 May 2007 03:13

Xpath to SQL Query with a number and subselect

Hi

I was wondering if someone can help me translate a Xpath query into SQL one.
The XPath query works like a charm untill you pass in a path with a number....

WORKS:
/jcr:root/site1/news//element(*,nt:base)[ <at> tag='news' and
MetaData/ <at> mgnl:template='np-article'] order by  <at> date descending

FAILS:
/jcr:root/site1/news/2007//element(*,nt:base)[ <at> tag='news' and
MetaData/ <at> mgnl:template='np-article'] order by  <at> date descending

Reason why it fails is outlined here (http://issues.apache.org/jira/browse/JCR-579)



My attempts to convert this to SQL query have failed as it seems impossible to put child into a predicate...
Here is what I have (but it does not work):

SELECT * FROM nt:base WHERE jcr:path LIKE '/site1/news/2007[%]/%' AND tag='news' AND mgnl:template='np-article'


The query will work with one AND predicate but not both...

Any help is appreciated.


Regards
Amir

(Continue reading)

ruchi goel | 2 May 2007 09:20
Picon

Re: // in xpath does not match immediate children

Hi Philips ,
   I am doing the same but it works.
Say , eg. I want all documents under /cms/childfolder1 which have author 
as "sushma", any of the following queries returns me the documents which 
are authored by 'sushma'

    *  /jcr:root/cms/childfolder1//*[ <at> ps:author='sushma'] 
    * /jcr:root/cms/childfolder1/element(*,ps:document)[ <at> ps:author='sushma']

Is the space between your search string 'tag' + space + '1' a problem ?

Did you try testing it via eclipse Jackrabbit Viewer plugin ?

-Ruchi

Phillip Rhodes wrote:
> Hello everyone,
>
> I am using jackrabbit to store "tags" that a user creates. 
> Given a structure (below) where each leaf node has an attribute of CONTENT_TYPE with a value of "Tag"
> /myfolder/tag 1/Tag 1
> /myfolder/tag 2/Tag 2
> /myfolder/tag 3/Tag 3
>
> My application needs to be able to query for what tags exist under a node path 
> e.g. 
> what tags are under /myfolder/tag 1?
> what tags are usder /myfolder/?
>
> My problem is that my xpath expression is not working for queries that pass the tag parent in as a node to look down.
(Continue reading)

Marcel Reutegger | 2 May 2007 11:10
Picon

Re: Xpath query with number

Hi Amir,

Amir Mistric wrote:
> According to this issue (http://issues.apache.org/jira/browse/JCR-579) , Id
> be better off to use SQL syntax. But now I have a different problem...How do
> I achieve the same result in SQL? I haven't been able to query MetaData
> part..

I think you should still use XPath and use the encoding as specified in jsr 170.

> In another words this does not work:
> 
> SELECT * FROM nt:base WHERE jcr:path LIKE
> '/www-site1-org/mediaroom/press/2006[%]/%' AND tag='news' AND
> mgnl:template='np-article'
> 
> I am guessing because 'tag' and 'mgnl:template' are not on the same
> "level"....

The query you have cannot be expressed in SQL because SQL does not support 
relative paths in an expression.

> Any help is appreciated...

You should use XPath and encode the node name:

/jcr:root/www-site1-org/mediaroom/press/_x0032_006//element(*,nt:base)[ <at> tag='news' 
and MetaData/ <at> mgnl:template='np-article'] order by  <at> date descending

regards
(Continue reading)

Kalyan Sarkar | 2 May 2007 11:57
Picon
Favicon

Parse Exception while registering node types


Hello everybody,
I am getting a ParseException when I try to create a
CompactNodeTypeDefReader instance.

org.apache.jackrabbit.core.nodetype.compact.ParseException: Error while
parsing 'repro:base' (reproNodeType.cnd
, line 1)
        at
org.apache.jackrabbit.core.nodetype.compact.Lexer.fail(Lexer.java:152)
        at
org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.toQName(CompactNodeTypeDefReade
r.java:637)
        at
org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.doNodeTypeName(CompactNodeTypeD
efReader.java:255)
        at
org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.parse(CompactNodeTypeDefReader.
java:205)
        at
org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.<init>(CompactNodeTypeDefReader
.java:168)
        at
org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.<init>(CompactNodeTypeDefReader
.java:153)
        at
com.anshinsoft.repro.JackrabbitDeployer.contextInitialized(JackrabbitDeployer.java:242)

Here is my .cnd file....

(Continue reading)

Jacco van Weert | 2 May 2007 12:04
Picon

Re: Parse Exception while registering node types

Hello,

You also defined the namespaces at the start of the CND file?

e.g.

<nt = 'http://www.jcp.org/jcr/nt/1.0'>
<mix = 'http://www.jcp.org/jcr/mix/1.0'>
<repro = 'http://www........'>

On 5/2/07, Kalyan Sarkar <kalyansarkar108 <at> yahoo.co.in> wrote:
>
>
> Hello everybody,
> I am getting a ParseException when I try to create a
> CompactNodeTypeDefReader instance.
>
> org.apache.jackrabbit.core.nodetype.compact.ParseException: Error while
> parsing 'repro:base' (reproNodeType.cnd
> , line 1)
>         at
> org.apache.jackrabbit.core.nodetype.compact.Lexer.fail(Lexer.java:152)
>         at
>
> org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.toQName
> (CompactNodeTypeDefReade
> r.java:637)
>         at
>
> org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader.doNodeTypeName
(Continue reading)

Kalyan Sarkar | 2 May 2007 12:30
Picon
Favicon

Re: Parse Exception while registering node types


No I didn't. Should I?
I registered the namespace 'repro' programmatically.

Jacco van Weert wrote:
> 
> Hello,
> 
> You also defined the namespaces at the start of the CND file?
> 
> e.g.
> 
> <nt = 'http://www.jcp.org/jcr/nt/1.0'>
> <mix = 'http://www.jcp.org/jcr/mix/1.0'>
> <repro = 'http://www........'>
> 
> 
> On 5/2/07, Kalyan Sarkar <kalyansarkar108 <at> yahoo.co.in> wrote:
>>
>>
>> Hello everybody,
>> I am getting a ParseException when I try to create a
>> CompactNodeTypeDefReader instance.
>>
>> org.apache.jackrabbit.core.nodetype.compact.ParseException: Error while
>> parsing 'repro:base' (reproNodeType.cnd
>> , line 1)
>>         at
>> org.apache.jackrabbit.core.nodetype.compact.Lexer.fail(Lexer.java:152)
>>         at
(Continue reading)

Jukka Zitting | 2 May 2007 13:43
Picon
Gravatar

Re: Parse Exception while registering node types

Hi,

On 5/2/07, Kalyan Sarkar <kalyansarkar108 <at> yahoo.co.in> wrote:
> I have programmatically registered the namespace 'repro' before this code
> fragment.
>
> The interesting part is that when I register the nodetypes through
> JackrabbitNodetypeManager I dont get the exception. For e.g.
>
> NodeTypeManagerImpl manager = (NodeTypeManagerImpl) ws.getNodeTypeManager();
> manager.registerNodeTypes(in, NodeTypeManagerImpl.TEXT_X_JCR_CND);
>
> Can anybody tell me what am I missing.

The NodeTypeManagerImpl class automatically makes all the registered
namespaces available to the CND parsers. If you instantiate the parser
directly, you need to explicitly add the namespaces you use. In any
case it's a good idea to include all namespace mappings in the CND
file.

BR,

Jukka Zitting


Gmane