Java tutorial
//package com.java2s; //License from project: Apache License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; public class Main { @SuppressWarnings({ "unchecked", "restriction" }) public static <T> T fromXML(String xml, Class<T> valueType) { try { JAXBContext context = JAXBContext.newInstance(valueType); Unmarshaller unmarshaller = context.createUnmarshaller(); return (T) unmarshaller.unmarshal(new StringReader(xml)); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } }