Java tutorial
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void Object2XmlFile(Object ob, String path) throws JAXBException, FileNotFoundException { Class local = ob.getClass(); JAXBContext context = JAXBContext.newInstance(new Class[] { local }); Marshaller marshaller = context.createMarshaller(); // marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", // paramNamespacePrefixMapper); // marshaller.setProperty("jaxb.formatted.output", // Boolean.valueOf(true)); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(ob, new FileOutputStream(new File(path))); } }