Java tutorial
//package com.java2s; //License from project: LGPL import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import java.io.File; public class Main { public static <T> T loadXML(Class<T> type, File sourceFile) { try { JAXBContext context = JAXBContext.newInstance(type); return (T) context.createUnmarshaller().unmarshal(sourceFile); } catch (JAXBException e) { throw new RuntimeException(e); } } }