Java tutorial
//package com.java2s; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import org.w3c.dom.Node; public class Main { public static <T> T UnMarshall(Class<T> objectClass, String filePath) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(objectClass); Unmarshaller u = jc.createUnmarshaller(); File f = new File(filePath); return objectClass.cast(u.unmarshal(f)); } public static <T> T UnMarshall(Class<T> objectClass, Node node) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(objectClass); Unmarshaller u = jc.createUnmarshaller(); return objectClass.cast(u.unmarshal(node)); } public static <T> T UnMarshall(Class<T> objectClass, XMLStreamReader reader) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(objectClass); Unmarshaller u = jc.createUnmarshaller(); return objectClass.cast(u.unmarshal(reader)); } }