3

As shown in the title,I define a String using '&' in strings.xml file,but the android studio show a error? strings.xml

<string name="url">
    url?locale=zh&articleNo=
</string>

Problems can be redefined:

We can't using special characters which have special meaning in XML.

The question is the XML syntax problems.

2 Answers2

5

Use &amp; instead of just &

UPD:
Answer to "Why can't you use &" is: it is by design: http://www.w3.org/TR/xml/#charsets

The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

krossovochkin
  • 12,030
  • 7
  • 31
  • 54
  • Yes,it's work.But why? –  Nov 05 '14 at 07:06
  • It's a problem of The XML syntax.[Here](http://stackoverflow.com/questions/7823813/how-can-i-use-character-in-xml-code) is a good answer. –  Nov 05 '14 at 07:32
2

For special character I normally use the Unicode definition, for the '&' for example: \u0026 if I am correct. Here is a nice reference page: http://jrgraphix.net/research/unicode_blocks.php?block=0

amit kumar
  • 291
  • 1
  • 6