Here you can find the source of getXmlString(T jaxbObject)
public static <T> String getXmlString(T jaxbObject) throws JAXBException
//package com.java2s; //License from project: Apache License import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static <T> String getXmlString(T jaxbObject) throws JAXBException { StringWriter sw = new StringWriter(); JAXBContext context = JAXBContext.newInstance(jaxbObject.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(jaxbObject, sw);/* w w w . j a v a 2 s .c o m*/ return sw.toString(); } }