How to escape a less-than ('<') character in a jcr:root element property | Community
Skip to main content
Level 2
Mar 3, 2022 11:43 PM UTC
Solved

How to escape a less-than ('<') character in a jcr:root element property

This is the code I have at /etc/map.prod.publish/https/mysite.net/content/.content.xml to redirect some matching URLs. I'm trying to use a regular expression with a backreference, but when I go to publish the changes, I get an error about the '<' character not being allowed in the sling:match property. How do I escape that character? "&lt;" didn't work.

 

The code:

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="sling:Mapping" sling:match="^/*(?!$|(?:content|apps|etc|libs)/)(?:((?:(?=((?=([^/]+))\\3/+))\\2)*)([^/]+)(?<!\\.html)(?:(\\.html)|/+))$" sling:redirect="[/$1$4]" sling:status="302" />

 

The error message:

03.03.2022 18:25:11.369 *ERROR* [qtp1433131481-1750] org.apache.jackrabbit.vault.fs.io.Importer E /etc/map.prod.publish/https/mysite.net/content (org.xml.sax.SAXParseException; systemId: file:///C:/AEM/mysite.net/author/jcr_root/etc/map.prod.publish/https/mysite.net/content/.content.xml; lineNumber: 5; columnNumber: 99; The value of attribute "sling:match" associated with an element type "jcr:root" must not contain the '<' character.)

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Mar 7, 2022 11:44 AM UTC

try with &lt;

 

<?xml version="1.0" encoding="UTF-8"?> 
<jcr:root xmlns:sling ="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr ="http://www.jcp.org/jcr/1.0" jcr:primaryType ="sling:Mapping" sling:match ="^/*(?!$|(?:content|apps|etc|libs)/)(?:((?:(?=((?=([^/]+))\\3/+))\\2)*)([^/]+)(?&lt;!\\.html)(?:(\\.html)|/+))$" sling:redirect ="[/$1$4]" sling:status ="302"/>
Arun Patidar

6 replies

arunpatidar
arunpatidarAccepted solution
New Participant
Mar 7, 2022 11:44 AM UTC

try with &lt;

 

<?xml version="1.0" encoding="UTF-8"?> 
<jcr:root xmlns:sling ="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr ="http://www.jcp.org/jcr/1.0" jcr:primaryType ="sling:Mapping" sling:match ="^/*(?!$|(?:content|apps|etc|libs)/)(?:((?:(?=((?=([^/]+))\\3/+))\\2)*)([^/]+)(?&lt;!\\.html)(?:(\\.html)|/+))$" sling:redirect ="[/$1$4]" sling:status ="302"/>
Translate
Arun Patidar
Level 2
Mar 7, 2022 12:31 PM UTC

It doesn't need to be escaped. I found another error further up in the log and resolved it. This was just some weird side effect. 

Translate
Anish-Sinha
Employee
Mar 4, 2022 2:46 AM UTC

Hi @wizard04wsu ,
I did try the regex in my local system and it does work and not breaking. Which AEM version are your using? Also, can you try putting an escape character in front of "<" and check if this fixes. Use below regex:

^/*(?!$|(?:content|apps|etc|libs)/)(?:((?:(?=((?=([^/]+))\\3/+))\\2)*)([^/]+)(?\<!\\.html)(?:(\\.html)|/+))$
Translate
Level 2
Mar 4, 2022 5:01 PM UTC

I'm using AEM 6.5. I tried escaping with a backslash, but got the same result.

Translate