Java tutorial
//package com.java2s; import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Main { public static String bean2XML(Object obj) throws Exception { JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller m = context.createMarshaller(); StringWriter sw = new StringWriter(); m.marshal(obj, sw); return sw.toString(); } }