Java XML JAXB String to Object convertToXmlFile(File file, Object source, Class... type)

Here you can find the source of convertToXmlFile(File file, Object source, Class... type)

Description

convert To Xml File

License

Apache License

Declaration

public static void convertToXmlFile(File file, Object source,
            Class<?>... type) 

Method Source Code

//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);
        }
    }
}

Related

  1. convertStringToJAXB(String str)
  2. convertToJAXBException(String msg, Throwable e)
  3. convertToObject(Class clazz, InputStream inputStream)
  4. convertXmlFileToObject(Class clazz, String xmlPath)
  5. convertXmlToObj(Class clazz, String xmlStr)
  6. convertXMLToObject(byte[] data, Class clazz)
  7. converyToJavaBean(String xml, Class c)