Skip to content

Support writing an XML document type definition from StaxEventItemWriter [BATCH-2128] #1467

Open
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions