Android res/xml cannot escape apostrophe in any way

138 views Asked by At

I have some XML files in res/xml and I'm trying to escape characters as you would normally do in XML. I tried nearly every way possible:

<tag>Okay, I'll do it</tag>
<tag>Okay, I\'ll do it</tag>
<tag>Okay, I&apos;ll do it</tag>
<tag>Okay, I&#x27;ll do it</tag>
<tag>Okay, I&#39;ll do it</tag>

None of them work, when I parse the file with XmlPullParser, I always get only part of the text: Okay I, split where the apostrophe was.

I also tried parser.setFeature(Xml.FEATURE_RELAXED, true), as suggested here, without success.

Is there any reason to this or any to fix this behavior?

EDIT: After more testing, it looks like this issue only happens with the apostrophe and no other escaped characters like &amp;.

2

There are 2 answers

0
Nicolas On BEST ANSWER

I posted an issue here about this and I was told this was intended behavior and would not be fixed. That really makes no sense but what can I do.

I was proposed using the res/raw folder, but then XML won't be optimized so I just used backtick ` and replaced it in code with an apostrophe.

1
Amit Jangid On

Check this link and use the codes for your special characters.

For example: &#39 and add a semi-colon after 9 for '. I didn't add because it gets converted in to '.