当我将 Java 对象编组为 XML 时,在关闭根标记后会添加一些额外的字符。
以下是从 XML 解组到文件后保存生成的 java 对象的方法:
public void saveStifBinConv(ConversionSet cs, String xmlfilename) {
FileOutputStream os = null;
try {
os = new FileOutputStream(xmlfilename);
this.marshaller.marshal(cs, new StreamResult(os));
}
catch (IOException e) {
log.fatal("IOException when marshalling STIF Bin Conversion XML file");
throw new WmrFatalException(e);
}
finally {
if (os != null) {
try {
os.close();
}
catch (IOException e) {
log.fatal("IOException when closing FileOutputStream");
throw new WmrFatalException(e);
}
}
}
}
额外的字符在根标签的结束标签之后填充。
添加的字符是 XML 中的一些字符。例子:tractor-to-type><bin-code>239</bin-code><allowed>YES</allowed></extractor-to></extractor-mapping><extractor-mapping><e
我使用 Spring OXMJaxb2Marshaller
和 JAXB 2。
谢谢 ;)