1.unmarshal from file
"input.xml" -> Object
// unmarshal customer information from file
IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
FileInputStream in = new FileInputStream("input.xml");
Order order = (Order)uctx.unmarshalDocument(in, null);
2.marshal object to file
Object -> "out.xml"
// marshal object back out to file (with nice indentation, as UTF-8)
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(2);
FileOutputStream out = new FileOutputStream("out.xml");
mctx.setOutput(out, null);
mctx.marshalDocument(order);
本文介绍如何使用Java从XML文件中读取数据并将其转换为对象,同时也展示了如何将对象序列化回XML文件的方法。
2053

被折叠的 条评论
为什么被折叠?



