【发布时间】:2011-04-19 21:56:15
【问题描述】:
如何使用 Aegis 将类转换为 XML?
在网上找不到教程,只有随机代码。
【问题讨论】:
标签: java xml xml-binding aegis
如何使用 Aegis 将类转换为 XML?
在网上找不到教程,只有随机代码。
【问题讨论】:
标签: java xml xml-binding aegis
这会将其保存到文件中:
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 了解更多信息,除了将其序列化到文件之外,您还可以使用什么。
【讨论】:
aegis 而不是JAXB 吗?
CXF 发行版中有独立于 Web 服务使用 Aegis 的示例。
具体来说,`aegis_standalone' 样本是您想要查看的。
【讨论】:
<apache-cxf-install-dir>\samples\ 目录下。