Java examples for XML:JAXB
Unmarshall to Object via JAXB
//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 void main(String[] argv) throws Exception { Class clazz = String.class; String name = "java2s.com"; System.out.println(load(clazz, name)); }/* w w w . ja v a2s .com*/ public final static Object load(Class clazz, String name) { try { File file = new File(name); JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller jaxbUnmarshaller = jaxbContext .createUnmarshaller(); return jaxbUnmarshaller.unmarshal(file); } catch (JAXBException e) { e.printStackTrace(); return null; } } }