In my Java application, I need to parse an XML document that contains control character 0x2
inside CDATA.
I tried few ways but coudnt get through. I want to avoid any sort of encoding.
Is there any way in XML1.1?
I need to parse xml that contains control character 0x2 inside CDATA
That's not XML, then. A raw control character U+0002 anywhere means it's not well-formed and hence not an XML document.
In XML 1.1 only, one may include control characters encoded as character reference. So you might have tried to fix it up by doing a string replace for \x02
with 
before parsing. However, you can't put character references in CDATA sections, so that's not going to fly either.
edit: you could probably fix it in the short-term, if you are absolutely sure that every stray U+0002 character is inside a CDATA section, by replacing each with:
]]><![CDATA[
However this is super-shonky. Whatever generated the faulty XML in the first place needs to be fixed. Go kick the person responsible for creating it!
XML cannt contain ASCII control characters (apart from TAB, CR and LF), not even inside a CDATA section. They are disallowed by the XML spec.
Encode binary data into Base64 strings and write them to XML. No need for CDATA in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With