Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

xpath query containing curly braces not working

Avatar

Former Community Member

I need to execute a xpath query containing curly braces. 

/jcr:root/content/myWebsite//*[jcr:contains(., '{{mySearchString)] order by @jcr:score

Is there any way to escape curly braces in AEM xpath query?

2 Replies

Avatar

Former Community Member

I don't think there's any way to directly escape the curly brace, but you can replace it with its Unicode Escape Sequence:

\u007B

jcr:contains is made to handle Lucene syntax, and curly braces are the way to denote an exclusive range search. So, I think it's by design that you can't directly escape it.
 

In any case, you should be able to replace your above example search with the following (assuming you accidentally left off the closing single-quote after mySearchString above):

/jcr:root/content/myWebsite//*[jcr:contains(., '\u007B\u007BmySearchString')] order by @jcr:score

 

If you need to do the same for other characters (e.g. the closing curly brace - which is \u007D), you can check here to find the character code: http://unicode.org/charts/

One or more of the these articles may help you to understand this better, in case you are interested:
https://lucene.apache.org/core/3_6_0/queryparsersyntax.html#Range Searches
https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.3
https://mathiasbynens.be/notes/javascript-escapes

 

Kind regards,

- Carey

Avatar

Level 1

Hi Carey,

I'd like to do the same kind of search, and I tried your tip but unfortunately it doesn't work ...

For exemple:

/jcr:root//*[jcr:contains(@*, '\u007Bwizard\u007D')]

give the exact same results as without the curly brace:

/jcr:root//*[jcr:contains(@*, 'wizard')]

i.e it find every element who contains the single "wizard" word and not filtering on "{wizard}"

I tried escaping the curly brace by different manner: "\{ ... \}" or also "{{ ... }}", nothing work :(