Java tutorial
//package com.java2s; import java.beans.XMLEncoder; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; public class Main { public static String parseObj2Xml(Object object) throws Exception { XMLEncoder encoder = null; String str = null; BufferedOutputStream bufOut = null; ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); bufOut = new BufferedOutputStream(out); encoder = new XMLEncoder(bufOut); encoder.writeObject(object); encoder.close(); str = new String(out.toByteArray()); } catch (Exception ex) { throw ex; } finally { if (out != null) out.close(); if (bufOut != null) bufOut.close(); } return str; } }