Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;

import javax.xml.bind.Unmarshaller;

import javax.xml.transform.stream.StreamSource;

public class Main {
    public static Object parseXmlFileToBeanByJAXB(String path, Class clase) throws Exception {

        JAXBContext context = JAXBContext.newInstance(clase);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement elm = unmarshaller.unmarshal(new StreamSource(new File(path)), clase);

        return elm.getValue();

    }
}