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

时间:2022-04-04 00:57:27

How to convert a class into XML with Aegis?
Can´t find tutorials on the web, only random code.

如何使用Aegis将一个类转换成XML ?只能´t在网上找到教程,随机代码。

2 个解决方案

#1


4  

This will save it to a file :

这将把它保存到一个文件:

 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")));

        }

Take a look at http://download.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html for more info what you can use beside serializing it to a file.

查看http://download.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html,了解更多信息,除了将其序列化为文件之外,还可以使用什么。

#2


2  

There are samples in the CXF distribution of using Aegis independently of web services.

在CXF发行版中,有一些示例独立于web服务使用Aegis。

Specifically, the `aegis_standalone' sample is what you want to look at.

具体来说,“aegis_independent”示例就是您希望查看的内容。

#1


4  

This will save it to a file :

这将把它保存到一个文件:

 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")));

        }

Take a look at http://download.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html for more info what you can use beside serializing it to a file.

查看http://download.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html,了解更多信息,除了将其序列化为文件之外,还可以使用什么。

#2


2  

There are samples in the CXF distribution of using Aegis independently of web services.

在CXF发行版中,有一些示例独立于web服务使用Aegis。

Specifically, the `aegis_standalone' sample is what you want to look at.

具体来说,“aegis_independent”示例就是您希望查看的内容。