Here you can find the source of convertToXmlFile(File file, Object source, Class>... type)
public static void convertToXmlFile(File file, Object source, Class<?>... type)
//package com.java2s; //License from project: Apache License import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { public static void convertToXmlFile(File file, Object source, Class<?>... type) { System.out.println("Generando Archivo: " + file.getName()); System.out.println("#############################"); try {// w w w .j a v a 2 s. c om JAXBContext jaxbContext = JAXBContext.newInstance(type); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(source, file); marshaller.marshal(source, System.out); } catch (JAXBException e) { throw new RuntimeException(e); } } }