Java tutorial
//package com.java2s; import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static String convertToXmlString(Object source) { try { StringWriter sw = new StringWriter(); JAXBContext jAXBContext = JAXBContext.newInstance(source.getClass()); Marshaller marshaller = jAXBContext.createMarshaller(); marshaller.marshal(source, sw); return sw.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } } }