Here you can find the source of xmlToJaxb(Class> xmlClass, String xml)
public static JAXBElement<?> xmlToJaxb(Class<?> xmlClass, String xml) throws JAXBException
//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); }/* w w w.ja v a2 s. co m*/ return element; } }