Java tutorial
//package com.java2s; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static Object xmlTobean(String path, String classPath) { Object obj = null; Class<?> obClass = null; try { obClass = Class.forName(classPath); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { File file = new File(path); JAXBContext context = JAXBContext.newInstance(obClass); Unmarshaller unmarshaller = context.createUnmarshaller(); obj = unmarshaller.unmarshal(file); System.out.println(obj); } catch (JAXBException e) { e.printStackTrace(); } return obj; } }