Here you can find the source of createXML(Object o)
public static String createXML(Object o) throws JAXBException
//package com.java2s; //License from project: LGPL 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 createXML(Object o) throws JAXBException { // Creating a Marshaller JAXBContext jaxbContext = JAXBContext.newInstance(o.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter result = new StringWriter(); jaxbMarshaller.marshal(o, result); // Printing XML String xml = result.toString(); //System.out.println(xml); return xml; }/*from w w w . j a v a2 s . c om*/ }