Java tutorial
//package com.java2s; import java.io.ByteArrayInputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; public class Main { public static Object xmlStrToObj(String inputStr, Class inputClass) throws Exception { byte[] byteArray = inputStr.getBytes(); ByteArrayInputStream byteStream = new ByteArrayInputStream(byteArray); XMLInputFactory input = XMLInputFactory.newFactory(); XMLStreamReader reader = input.createXMLStreamReader(byteStream); JAXBContext context = JAXBContext.newInstance(inputClass); Unmarshaller unmarsh = context.createUnmarshaller(); Object result = unmarsh.unmarshal(reader); return result; } }