Java tutorial
//package com.java2s; import java.beans.XMLEncoder; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { public static String toXml(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(baos); e.writeObject(o); e.close(); return baos.toString(); } }