BufferedWriter out = new BufferedWriter(fstream);
try {
JAXBContext context = JAXBContext.newInstance(NarociloType.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(parameters, out);
out.newLine();
} catch (PropertyException pe) {
// TODO: Add catch code
pe.printStackTrace();
} catch (JAXBException jaxbe) {
// TODO: Add catch code
jaxbe.printStackTrace();
}
但空類型不存儲到XML中。例如:使用JAXBContext和Marshaller將對象與XML和XML對象
NarociloType.date = null
但我不能在xml中看到<date></date>
。 JAXB編組不會爲空值創建空元素
我還可以使用JAXBContext更改XML以反對對象嗎?
嗨,thx的答案,但我使用JDeveloper 11g,如果我仍然使用jaxb.properties使用舊的javax.xml.bind.JAXBContext; – senzacionale 2011-06-20 05:43:06
@senzacionale - 您將需要包含eclipselink.jar文件。你可以在這裏獲得一個:http://www.eclipse。組織/的EclipseLink /下載/ – 2011-06-20 20:42:08