How to convert Java to XML using Aegis?

901 views Asked by At

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

2

There are 2 answers

7
ant On BEST ANSWER

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.

4
bmargulies On

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

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