Java tutorial
//package com.java2s; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.StringWriter; public class Main { private static final String noResult = "<result>no result</result>"; private static String parseObject2XmlString(Object object) { if (object == null) { return noResult; } StringWriter sw = new StringWriter(); JAXBContext jaxbContext; Marshaller marshaller; try { jaxbContext = JAXBContext.newInstance(object.getClass()); marshaller = jaxbContext.createMarshaller(); marshaller.marshal(object, sw); return sw.toString(); } catch (JAXBException e) { e.printStackTrace(); return noResult; } } }