Java tutorial
//package com.java2s; import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { @SuppressWarnings("unchecked") public static <T> T toXML(Class<T> cls, String xml) { try { return (T) JAXBContext.newInstance(cls).createUnmarshaller().unmarshal(new StringReader(xml)); } catch (JAXBException e) { return (T) "<>"; } } }