Android layout file does not allow characters like &, <,>

When I tried to use &, <,> as text of a text view, both in main.xml and in the strings.xml file, it returns an error. I want to show "&", "<" anyway, in a text view. How to do it?

Please advise me.

Thanks in advance.

+3
source share
3 answers

As pointed out by @Welbog, there are 5 XML escape sequences:

"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;

Source: Symbols for deleting XML documents

+8
source

I do not know Android, but in using XML

<   =   &lt;
>   =   &gt;
&   =   &amp;
"   =   &quot;
'   =   &apos;

Or use CDATAfor example

<![CDATA[
    my String with 
    special chars like
    >, < and &
    normally not allowed in XML!
]]>

1 escape XML. @mikaveli

+3

This is XML. You have to run away from them. Maybe you should learn XML before using XML-based layout language?

< &lt;
> &gt;
& &amp;
" &quot; (in attributes)
' &apos; (in attributes)
+1
source

Source: https://habr.com/ru/post/1790275/


All Articles