Java tutorial
//package com.java2s; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static <T> void xmlWriter(T entity, String xmlDestinationPath) { try { JAXBContext jc = JAXBContext.newInstance(entity.getClass()); File destinationFile = new File(xmlDestinationPath); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(entity, destinationFile); } catch (JAXBException ex) { } } }