Here you can find the source of getXMLString(Object person, Class> clazz)
public static String getXMLString(Object person, Class<?> clazz) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { public static String getXMLString(Object person, Class<?> clazz) throws JAXBException { StringWriter sw = new StringWriter(); JAXBContext context = JAXBContext.newInstance(clazz); context.createMarshaller().marshal(person, sw); String output = sw.toString(); System.out.println(output); return output; }//from w ww . ja v a 2s .c o m }