Parsing xml containing symbol reference

The XML file trying to parse contains a 0x2 control character inside CDATA. I tried to replace it with a symbol reference which resulted in the CDATA looking like this:

CDATA section----charcter reference----CDATA section

      

Now if I try to parse it I get the error: org.xml.sax.SAXParseException: Content is not allowed in the prologue.

The original xml looked like this:

<?xml version="1.1" encoding="UTF-16"?><CELL><![CDATA[ABCD&#2;EFGH]]></CELL>

      

I changed it to:

<?xml version="1.1" encoding="UTF-16"?><CELL><![CDATA[ABCD]]>&#2;<![CDATA[EFGH]]></CELL>

      

+2


a source to share


1 answer


Entity definitions are not allowed in CDATA sections, so your original example doesn't work. The fact that the modified example doesn't work is, in my opinion, a bug in the SAX parser. The SAX parser may not allow you to mark invisible byte order (BOM) before the XML prologue that starts with <?, But the SAX parser should.

To help the SAX parser it will eventually lead to the following workaround. Namely, consuming the BOM before feeding the analyzer. For this purpose, you can use a marked stream, i.e. Marking the stream, reading the specification, reprogramming the stream to its label if there was no specification. I haven't tried, it's just a guess.



BTW: Your question will be better received if you correct the typo in the introduction: write "character reference" instead of "charcter reference". At first I thought the missing a was related to your question.

0


a source







All Articles