1

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

Nicolas
  • 6,611
  • 3
  • 29
  • 73

2 Answers2

0

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

Amit Jangid
  • 2,741
  • 1
  • 22
  • 28
  • No that doesn't work but I had actually made a mistake and wrote `Y` and I realized that it worked. It seems to only fail when the character is an apostrophe, but it works for `&`. Very weird. – Nicolas Apr 10 '18 at 11:46
0

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.

Nicolas
  • 6,611
  • 3
  • 29
  • 73