Here you can find the source of loadXMLFromString(Object object, String line)
public static Object loadXMLFromString(Object object, String line)
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static Object loadXMLFromString(Object object, String line) { Unmarshaller unmarshaller = createUnmarshaller(object); Object loaded = null;/*from w w w . ja v a2 s. co m*/ StringReader stringReader = new StringReader(line); if (!line.isEmpty()) { try { loaded = unmarshaller.unmarshal(stringReader); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return loaded; } @SuppressWarnings("rawtypes") private static Unmarshaller createUnmarshaller(Object object) { Class objectClass = object.getClass(); if (objectClass.getSimpleName().equals("Class")) { objectClass = (Class) object; } JAXBContext context; Unmarshaller unmarshaller = null; try { context = JAXBContext.newInstance(objectClass); unmarshaller = context.createUnmarshaller(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } return unmarshaller; } }