Here you can find the source of toXML(Object o, OutputStream os)
public static void toXML(Object o, OutputStream os) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.OutputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void toXML(Object o, OutputStream os) throws JAXBException { JAXBContext context = JAXBContext.newInstance(o.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(o, os);//from w w w. ja v a 2s.c o m } }