如何使用Aegis将类转换为XML?
在网上找不到教程,只有随机代码。
发布于 2011-04-20 06:01:44
这将把它保存到一个文件中:
public void saveToXML(YourDomainObject obj) throws JAXBException, IOException {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(obj, new FileWriter(new File("filename.xml")));
}看看http://download.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html,了解更多信息,除了将其序列化为文件外,还可以使用哪些内容。
发布于 2011-04-20 06:13:45
在独立于web服务使用Aegis的CXF发行版中有一些示例。
具体来说,`aegis_standalone的示例就是您想要查看的内容。
https://stackoverflow.com/questions/5723205
复制相似问题