My question is similar to Why are "control" characters illegal in XML 1.0? - however I'm looking for a solution to the problem below, rather than why the XML spec disallows control characters in XML.
I have a servlet, which prints a String containing an XML upon user request. One particular element contains a CDATA section which is required to contain some user input text.
Now it so happens that in one particular case, our user input contains the character U+0001 (a control character). And even though I specify the charset as UTF-8, the servlet throws an error:
Error: not well-formed
Location:
<![CDATA[
Is there a way I can process the Java String to make it "XML safe" ? Particularly, to make it safe when put in the CDATA section?
I hope my question is clear!
Thanks in advance, Raj