How to escape the < and ≤ symbols in xml?
Solution 1
You will have to escape those symbols as following:
-
<
will be<
-
>
will be>
The ≤
sign doesn't need escaping.
Solution 2
You have to escape those symbols for XML.
What characters do I need to escape in XML documents?
Solution 3
As said, for the <
and >
, you can use this:
< <
> >
You need to do this because the <
and >
aren't allowed in XML, so you need to escape
them. You do that by typing: &
+ specific code for your character
+ ;
, when you show this string, this will be recognized as being the special character (<
or >
).
You also wanted the smaller or equal
sign (≤), which is afaik allowed in XML, so just use ≤
.
These are the characters you have to escape:
" = "
' = '
< = <
> = >
& = &
Solution 4
Use this:
< <
> >
Solution 5
Use Unicode sequences for special characters.
You can find some of them here: http://jrgraphix.net/r/Unicode/2200-22FF
Use it like this:
\u2264
will be converted to ≤
user2301281
Programmer have no time to sleep, eventhough I'm not in such programmer level, I still have no time to SLEEP! I'm just can use my limited programming knowledge and English to study what I can learn. Thanks for everyone who's lend me a hand in this tough journey, appreciate it.
Updated on July 22, 2022Comments
-
user2301281 almost 2 years
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 ?
-
unwind over 10 yearsDoesn't this entierly miss the point of the "less than or equal" sign being used, ≤ ?
-
unwind over 10 years@peter.petrov Ah, I guess the OP's errors are only from the use of regular <.
-
peter.petrov over 10 yearsI think I answered first on this question btw :) @kocko Isn't this ≤ actually < ?!
-
user2301281 over 10 yearsit shown "unescaped & or nonterminated character/entity reference" error. when i use "<"
-
Konstantin Yovkov over 10 yearsyou will have to add a colon (
;
) after it. -
Selvin over 10 yearswhy it has +1? \uxxxx is not for xml
-
Selvin over 10 yearswhy it has +1? \uxxxx is not for xml
-
Lovis over 10 years@Selvin this is tagged android, and in strings.xml it 100% works PLUS its the only way to do it with some special chars, like "non breaking-hyphen" \uXXXX is even SUGGESTED BY LINT (e.g if you type "...")
-
Selvin over 10 yearssure the only way ....
<?xml version="1.0" encoding="utf-8"?> <root><test name="‑"/></root>
xml notation is &#XXXX; or &#xHHHH; -
Lovis over 10 years@selvin yes you're right (plus I just saw, that lint is not suggesting it anymore) BUT still, why is it thing working, if its not for xml?
-
Selvin over 10 yearsfrom The Source w3.org/TR/REC-xml/#dt-charref ... there is no single word about \u notation
-
Lovis over 10 yearsI still don't see why it's wrong. It answers the question and works in android. (why? Probably because the string is first parsed and then translated)