50
<string name="app_name">something & something</string> 

gives an error. How can i escape this?

Is this correct

<string name="app_name">something &amp; something</string>

or is there a better way?

mbrc
  • 3,523
  • 13
  • 40
  • 64

3 Answers3

112

Try reading this page: http://www.xmlnews.org/docs/xml-basics.html it looks like it contains the answer you are looking for.

In summary, here is the list of escaped characters and the escape code

Character  Predeclared Entity
&          &amp;
<          &lt;
>          &gt;
"          &quot;
'          &apos;

Referenced from the link.

robd
  • 9,646
  • 5
  • 40
  • 59
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
15

For me &quot ; didin't work so I used \"" and this character was escaped.

user1252459
  • 563
  • 7
  • 7
5

Well in Android XML simply adding the Predeclared entities didn't work in my case, needed to add a backslash before it. So in order to escape something & something use:

<string name="app_name">something \&amp; something</string>

In the case of apostrophe and quotes simply using a backslash works too. Like for escaping something like "That's it" you can simply use:

<string name="demo">\"That\'s it\"</string>

instead of the usual

<string name="demo">\&quot;That\&apos;s it\&quot;</string>

Hope this will be of help when someone like me stumbles on this question.

ljk
  • 1,496
  • 1
  • 11
  • 14