Java XML JAXB String to Object xmlToJaxb(Class xmlClass, String xml)

Here you can find the source of xmlToJaxb(Class xmlClass, String xml)

Description

xml To Jaxb

License

Open Source License

Declaration

public static JAXBElement<?> xmlToJaxb(Class<?> xmlClass, String xml) throws JAXBException 

Method Source Code

//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;
    }
}

Related

  1. toObject(String xml, Class clazz)
  2. xml2obj(final Class cls, final String xml)
  3. xml2Object(String content, Class valueType)
  4. Xml2Object(String xmlString, Class clazz)
  5. xmlToJavaBean(String xml, Class c)
  6. xmlToJaxb(Class xmlClass, String xml)
  7. xmlToObject(String xml, Class... type)
  8. xmlToObject(String xml, Class classe)
  9. XmlToObject(String xml, Class type)