Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 2

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.)

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

6 Replies

Avatar

Level 10

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)|/+))$

Avatar

Level 2

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

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 2

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. 

Avatar

Level 2

Also, please don't assume that your reply is the answer. If you can change the correct answer for this post, please do. 

Avatar

Community Advisor

Hi @wizard04wsu 

Could you please post a correct answer?

@kautuk_sahni - could you please change the correct answer as per @wizard04wsu response?