Currently I am using Castor framework to marshall the object into xml file it work greats
Writer writer = new FileWriter("D:/out.xml"开发者_运维技巧);
Marshaller.marshal(test, writer);
But now I am using javax.xml.bind to do the same thing.
Writer writer = new FileWriter("D:/out.xml");
JAXBContext context =
JAXBContext.newInstance(test.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(test, writer);
Then I hits this error message :
unable to marshal type "package1.Testing" as an element because it is missing an @XmlRootElement annotation]
Add the XmlRootElement
annotation and you won't get the error anymore. This should be added to the top-level or "root" class.
精彩评论