4

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.

0

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes,it's work.But why?
It's a problem of The XML syntax.Here is a good answer.
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

Comments