This escapes because the handler.characters function is intended to exit, and the <![CDATA[ part is not considered part of the value.
You need to use the newly opened methods in DefaultHandler2 or use the TransformerHandler approach, where you can set the CDATA_SECTION_ELEMENTS output key, which uses a list of tag names with a space that should output subtext sections enclosed in CDATA.
StreamResult streamResult = new StreamResult(out); SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler hd = tf.newTransformerHandler(); Transformer serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "column"); hd.setResult(streamResult); hd.startDocument(); hd.startElement("","","column",atts); hd.characters(asdf,0, asdf.length()); hd.endElement("","","column"); hd.endDocument();
source share