Problem with surrogate characters

Ilya Sokolov <[email protected]>
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <046318B5D1BBAC4D8769EF0DA2626F703036798149@TUS1XCHEVSPIN32.SYMC.SYMANTEC.COM>
Hi!

I have an issue parsing XML containing Unicode strings with surrogate characters (Xerces 2.11.0). The following exception is thrown:


        org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 18; Character reference "&#55360" is an invalid XML character.

        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)

        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)

Simple code to reproduce the issue:

         byte[] enc1 = new byte[] {(byte)0xd8, 0x40, (byte)0xdc, 0x2a};
         String result = new String(enc1, "UTF-16");
         System.out.println(result); // Outputs 𠀪 correctly

         String saml="<name>lz1&#55360;&#56362;.cct.cm</name>";
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document document= builder.parse(new InputSource(new StringReader(saml))); // Throws exception


Do I parse the XML correctly?

The XML I parse contains the following string:

lz1𠀪.cct.cm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.