Search code examples
xmlescaping

How to escape the < and ≤ symbols in xml?


I want to create a string <res> in android as below:

<string name="bmi0">0: BMI≤18.5</string>
<string name="bmi1">1: 18.5<BMI≤24</string>
<string name="bmi2">2: 24<BMI≤27</string>

But i shown the error of "Tag start is not closed".

I tried to put a \ symbol in front, but it doesn't work, it has shown the same error.

<string name="bmi0">0: BMI\≤18.5</string>
<string name="bmi1">1: 18.5<BMI\≤24</string>
<string name="bmi2">2: 24<BMI\≤27</string>

How to escape the special XML symbols ?


Solution

  • You will have to escape those symbols as following:

    • < will be &lt;
    • > will be &gt;

    The character doesn't need escaping.