276

I write

 <string name="magazine">Newspaper & Magazines</string>

in file strings.xml.

But the compiler says:

The entity name must immediately follow the '&' in the entity reference. strings.xml /OOReaderWidget/res/values line 9 Android XML Format Problem

How can I show a "&" in strings.xml?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
herbertD
  • 10,657
  • 13
  • 50
  • 77
  • XML and HTML are similar, but where is the corresponding canonical Stack Overflow question for HTML? (Many search engine hits end up here.) – Peter Mortensen Nov 08 '21 at 23:30

3 Answers3

528

Use &amp; in place of &.

Change it to:

<string name="magazine">Newspaper &amp; Magazines</string>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • 6
    Just in case anyone reaches this question the same i did, there is the list of escape characters in .xml files and how to escape them: https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/rwlp_xml_escape.html – Nisim Naim Jun 07 '18 at 06:25
102

& → &amp;

< → &lt;

> → &gt;

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xshoppyx
  • 1,444
  • 1
  • 8
  • 9
13

You can use &amp; in place of &

http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined%5Fentities%5Fin%5FXML

dub stylee
  • 3,252
  • 5
  • 38
  • 59
Kurt
  • 767
  • 8
  • 23