Java XML JAXB String to Object convertXmlFileToObject(Class clazz, String xmlPath)

Here you can find the source of convertXmlFileToObject(Class clazz, String xmlPath)

Description

convert Xml File To Object

License

Open Source License

Declaration

public static Object convertXmlFileToObject(Class<?> clazz, String xmlPath) 

Method Source Code


//package com.java2s;
import java.io.FileNotFoundException;
import java.io.FileReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

public class Main {

    public static Object convertXmlFileToObject(Class<?> clazz, String xmlPath) {
        Object xmlObject = null;//from w w  w .java2  s.  c o m
        try {
            JAXBContext context = JAXBContext.newInstance(clazz);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            FileReader fr = null;
            try {
                fr = new FileReader(xmlPath);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            xmlObject = unmarshaller.unmarshal(fr);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return xmlObject;
    }
}

Related

  1. convertStringToJAXB(String str)
  2. convertToJAXBException(String msg, Throwable e)
  3. convertToObject(Class clazz, InputStream inputStream)
  4. convertToXmlFile(File file, Object source, Class... type)
  5. convertXmlToObj(Class clazz, String xmlStr)
  6. convertXMLToObject(byte[] data, Class clazz)
  7. converyToJavaBean(String xml, Class c)
  8. converyToJavaBean(String xml, Class c)