如何使用 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有关更多信息,除了将其序列化为文件外,您还可以使用什么。
关于java - 如何使用 Aegis 将 Java 转换为 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5723205/