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

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

  • March 3, 2022
  • 2 replies
  • 1807 views

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.
Best answer by arunpatidar

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"/>

2 replies

Anish-Sinha
Adobe Employee
Adobe Employee
March 4, 2022

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)|/+))$
Level 2
March 4, 2022

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

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
March 7, 2022

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
Level 2
March 7, 2022

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.