woodstox
woodstox copied to clipboard
Invalid characters inside CDATA section
Example:
var factory = XMLOutputFactory.newInstance();
factory.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER, new ReplacingHandler('�'));
try (var output = Files.newOutputStream(Paths.get("/tmp/test.xml"))) {
XMLStreamWriter writer = factory.createXMLStreamWriter(output);
writer.writeStartDocument();
writer.writeStartElement("Test");
writer.writeCData("Text content\u001A...");
writer.writeEndElement();
writer.writeEndDocument();
writer.close();
}
In this case, the writer doesn't replace (or even check for) any invalid characters. The output contains the 0x1A codepoint inside the CDATA section, which isn't valid XML.