簡體   English   中英

如何使用Aegis將Java轉換為XML?

[英]How to convert Java to XML using Aegis?

如何使用Aegis將類轉換為XML?
在網上找不到教程,只能找到隨機代碼。

這會將其保存到文件中:

 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,以了解更多信息,除了將其序列化到文件之外,還可以使用什么。

CXF發行版中有一些示例,它們獨立於Web服務使用Aegis。

具體來說,您要查看“ aegis_standalone”示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM