Here you can find the source of marshallXml(final Object object)
static String marshallXml(final Object object)
//package com.java2s; import java.io.StringWriter; import java.util.Map; import java.util.Map.Entry; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { static String marshallXml(final Object object) { return marschall(object, null); }/*from w w w .j av a 2 s. c o m*/ private static String marschall(final Object object, final Map<String, Object> marchallerProps) { try { return marschallImpl(object, marchallerProps); } catch (final JAXBException e) { throw new RuntimeException(e); } } private static String marschallImpl(final Object object, final Map<String, Object> marchallerProps) throws JAXBException { final JAXBContext context = JAXBContext.newInstance(object.getClass()); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (marchallerProps != null) { for (final Entry<String, Object> property : marchallerProps.entrySet()) { marshaller.setProperty(property.getKey(), property.getValue()); } } final StringWriter stringWriter = new StringWriter(); marshaller.marshal(object, stringWriter); return stringWriter.toString(); } }