Here you can find the source of marshallToXml(String zpackage, Writer writer, Object data)
public static void marshallToXml(String zpackage, Writer writer, Object data)
//package com.java2s; //License from project: Apache License import java.io.Writer; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void marshallToXml(String zpackage, Writer writer, Object data) { JAXBContext jc;// w w w. j a v a 2 s . c o m try { jc = JAXBContext.newInstance(zpackage); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(data, writer); } catch (JAXBException e) { throw new RuntimeException(e); } } }