Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static JAXBElement<?> xmlToJaxb(Class<?> xmlClass, String xml) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<?> element; try (StringReader reader = new StringReader(xml)) { element = (JAXBElement<?>) unmarshaller.unmarshal(reader); } return element; } }