Description
Scott Rossillo opened BATCH-2128 and commented
It isn't possible to include an XML Document Type Definition in an XML document produced using the StaxEventItemWriter without extending the class and overriding startDocument(XMLEventWriter writer)
. The root node is already written when the header callback is called, so it cannot be inserted using a callback.
There's a decent amount of code in startDocument(XMLEventWriter writer)
that has to be duplicated when overriding this method. I'd either propose adding an option to specify a DTD or if you don't want StaxEventItemWriter to explicitly support DTDs, adding a simple method createStartDocument()
that can be overridden without requiring a full override of startDocument(XMLEventWriter writer)
.
protected void startDocument(XMLEventWriter writer) throws XMLStreamException {
XMLEventFactory factory = createXmlEventFactory();
// write start document
createStartDocument(writer);
// write root tag
// rest of method omitted for brevity
}
protected void createStartDocument(XMLEventWriter writer) throws XMLStreamException {
XMLEventFactory factory = createXmlEventFactory();
writer.add(factory.createStartDocument(getEncoding(), getVersion()));
}
I can send a pull request with whichever solution is preferred.
Affects: 2.2.2