本文介绍了如何删除StaxEventItemWriter< root>通过开始/结束文档方法添加的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除由开始/结束Document方法添加的StaxEventItemWriter标记?
How can I remove StaxEventItemWriter tag added by start/end Document methods ?
它是在生成XML文件时默认添加的,所以请任何人告诉我如何删除默认根标记.
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">
---
---
</..>
推荐答案
我结束了这样的事情:
/**
* {@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) { }
}
海事组织,这不是很干净,但也不是很糟糕.这样,您可以依靠StaxEventItemWriter类的每种机制,而无需编写根元素.
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.
这篇关于如何删除StaxEventItemWriter< root>通过开始/结束文档方法添加的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!