如何使用Aegis将Java转换为XML?

时间:2011-04-19 21:56:16

标签: java xml xml-binding aegis

如何使用Aegis将类转换为XML?
无法在网上找到教程,只能随机代码。

2 个答案:

答案 0 :(得分:4)

这会将其保存到文件中:

 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,了解有关在将其序列化为文件后可以使用的详细信息。

答案 1 :(得分:2)

CXF分发中有一些使用Aegis的样本,与Web服务无关。

具体来说,你想看的是'aegis_standalone'样本。

相关问题