问题
How can I remove StaxEventItemWriter tag added by start/end Document methods ?
It is added by default when I'm generating the XML file, So please can any one tell me how I can remove default root tag.
Ex-
<?xml version='1.0' encoding='UTF-8'?>
<root>
<ressourcespleiade date="2015-10-03 06:38:00.000">
---
---
</..>
回答1:
I ended doing something like this:
/**
* {@link StaxEventItemWriter} which write no root tag as written elements are root
* @param <T> Type of the written elements
*
* @author francois.dupire
*/
public class NoRootStaxEventItemWriter<T> extends StaxEventItemWriter<T> {
/*
* Methods
*/
@Override
protected void startDocument(XMLEventWriter writer) throws XMLStreamException {
XMLEventFactory factory = createXmlEventFactory();
// write start document
writer.add(factory.createStartDocument(getEncoding(), getVersion()));
}
@Override
protected void endDocument(XMLEventWriter writer) { }
}
IMO, that's not really clean, but not really bad either. That way you can rely on every mecanism of the StaxEventItemWriter class but writing no root element.
来源:https://stackoverflow.com/questions/49110971/how-can-i-remove-staxeventitemwriter-root-tag-added-by-start-end-document-meth