1

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

informatik01
  • 16,038
  • 10
  • 74
  • 104
bruno
  • 2,154
  • 5
  • 39
  • 64

2 Answers2

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.

ant
  • 22,634
  • 36
  • 132
  • 182
  • 1
    That can work using JAXB, but i wanna do it with AEGIS, but can´t figure out how to do it. – bruno Apr 19 '11 at 22:06
  • @bruno, sorry never heard of AEGIS until now – ant Apr 19 '11 at 22:10
  • @bruno - your post subject says using JAXB. Shouldn't it say aegis? Do you know why you want to use `aegis` instead of `JAXB` ? – CoolBeans Apr 19 '11 at 22:15
  • I said aegis nobody knew the answer... AEGIS is related to JAXB, that´s why. – bruno Apr 19 '11 at 22:23
  • AEGIS is only related to JAXB as they do similar things but they are not the same thing and your question does say JAXB which this answers, AEGIS is specific to CXF, JAXB is standards based, if you can go with JAXB. – vickirk Apr 19 '11 at 22:29
  • I´ve already done it with JAXB, now i need to do it with AEGIS. – bruno Apr 19 '11 at 22:33
  • 2
    Then look at the example suggested by @bmargulies or reword the question to to get answers to what you want ;-) Putting JAXB because not as many people know aegis is not going to attract any answers you want! – vickirk Apr 19 '11 at 22:36
2

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.

bmargulies
  • 97,814
  • 39
  • 186
  • 310