You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by James Hang <jh...@bea.com> on 2007/03/03 01:55:42 UTC

Escaping node names in xpath queries

We're having problems running an xpath query where a node name in the xpath
contains blank spaces.

For example, the following query won't work because of the blank space in
the name "Node A":

/jcr:root//mypath/Node A//element(*, myType) order by @cx:created ascending

We tried uri encoding the name, which replaces the space with %20, but that
gives us this error:

javax.jcr.query.InvalidQueryException: Lexical error at line 1, column 110. 
Encountered: "2" (50), after : "%": Lexical error at line 1, column 110. 
Encountered: "2" (50), after : "%": Lexical error at line 1, column 110. 
Encountered: "2" (50), after : "%"

Is there a way to get around this?

-- James

-- 
View this message in context: http://www.nabble.com/Escaping-node-names-in-xpath-queries-tf3336904.html#a9280479
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: [jira] Escaping node names in xpath queries

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 3/4/07, James Hang <jh...@bea.com> wrote:
> Thanks for the response.  Is there a Jackrabbit library that we can use to do
> this escaping for us?

Check out the org.apache.jackrabbit.util.ISO9075 class in the
jackrabbit-jcr-commons library. It contains static encode() and
decode() methods that implement the _x0000_  escaping mechanism used
in JCR.

BR,

Jukka Zitting

Re: [jira] Escaping node names in xpath queries

Posted by James Hang <jh...@bea.com>.
Thanks for the response.  Is there a Jackrabbit library that we can use to do
this escaping for us?  

James



Julian Reschke wrote:
> 
> James Hang schrieb:
>> We're having problems running an xpath query where a node name in the
>> xpath
>> contains blank spaces.
>> 
>> For example, the following query won't work because of the blank space in
>> the name "Node A":
>> 
>> /jcr:root//mypath/Node A//element(*, myType) order by @cx:created
>> ascending
>> 
>> We tried uri encoding the name, which replaces the space with %20, but
>> that
>> gives us this error:
>> 
>> javax.jcr.query.InvalidQueryException: Lexical error at line 1, column
>> 110. 
>> Encountered: "2" (50), after : "%": Lexical error at line 1, column 110. 
>> Encountered: "2" (50), after : "%": Lexical error at line 1, column 110. 
>> Encountered: "2" (50), after : "%"
>> 
>> Is there a way to get around this?
> 
> XPath goes against the "document view" of the repository, thus you have 
> escape names using the rules in JSR 170, Section 6.4.3.
> 
> For instance, a space character would become "_x0020_".
> 
> Best regards, Julian
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A-Escaping-node-names-in-xpath-queries-tf3337993.html#a9290363
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: Escaping node names in xpath queries

Posted by Julian Reschke <ju...@gmx.de>.
James Hang schrieb:
> We're having problems running an xpath query where a node name in the xpath
> contains blank spaces.
> 
> For example, the following query won't work because of the blank space in
> the name "Node A":
> 
> /jcr:root//mypath/Node A//element(*, myType) order by @cx:created ascending
> 
> We tried uri encoding the name, which replaces the space with %20, but that
> gives us this error:
> 
> javax.jcr.query.InvalidQueryException: Lexical error at line 1, column 110. 
> Encountered: "2" (50), after : "%": Lexical error at line 1, column 110. 
> Encountered: "2" (50), after : "%": Lexical error at line 1, column 110. 
> Encountered: "2" (50), after : "%"
> 
> Is there a way to get around this?

XPath goes against the "document view" of the repository, thus you have 
escape names using the rules in JSR 170, Section 6.4.3.

For instance, a space character would become "_x0020_".

Best regards, Julian