I need to write a text with the unicode character 0x1F in a utf-8 document (it is not an allowed character in xml). Is there a way to escape it, or do I have to discard it?
Asked
Active
Viewed 2.1k times
2 Answers
9
This will do it in XML 1.1 (but is discouraged):

It isn't supported at all in XML 1.0. A workaround is to base-64 encode the text containing the character.

David M
- 71,481
- 13
- 158
- 186
-
3Well, that is the same thing, but it is just as illegal. xmllint for example: test.xml:2: parser error : xmlParseCharRef: invalid xmlChar value 31 – Filip Jul 23 '09 at 08:15
-
can you please explain it. how can i use while parsing the xml which contains 0x1f char – Mohit Singh Jun 28 '17 at 09:09
3
Using 0x1F XML is illegal (http://www.w3.org/TR/xml11/#charsets). so there is no way to do it, except from encoding it yourself in some way. base-64 (as proposed), or url encode, or any other option that the xml does not understand. It is the same problem as storing binary data in xml.

Mihai Nita
- 5,547
- 27
- 27