Search code examples
xmljava-mespecial-characterskxml2

Special character problem in J2ME


I am reading unicode character from XML like \u09A8\u09AC\u09AE. I have used <?xml version="1.0" encoding="utf-8"?> in the heading of XML. When I parsing xml from server using KXML2 parser it makes every unicode character a string. If I convert it to character array it gives like :

Char 0: \

Char 1: u

Char 2: 0

Char 3: 9

Char 4: B

Char 5: E

How can I get my unicode character back?


Solution

  • In XML \u09A8 is not a Unicode character reference in XML!

    There are only a few places that treat \u as the beginning of a Unicode escape, and they are mostly in the Java area.

    In XML a hexidecimal Unicode escape would be &#x09A8; and a decimal one would be &#2472;.

    In other words: You get the characters \, u, 0, 9, B, E back, because that's what the XML contains.

    The best solution is to fix whatever produces this XML to use actual numeric entity references. Alternatively, you can manually replace the \u escapes with their corresponding characters, but then only your code will correctly interpret this non-standard XML.