Java tutorial
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void writeXML(Class<?> class1, Object obj, File outputFile) throws JAXBException, FileNotFoundException { JAXBContext context = JAXBContext.newInstance(class1); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(obj, outputFile); } }