Java XML JAXB Unmarshaller unmarshall(String xml, URL schemaURL, Class... classesToBeBound)

Here you can find the source of unmarshall(String xml, URL schemaURL, Class... classesToBeBound)

Description

unmarshall

License

Open Source License

Declaration

public static Object unmarshall(String xml, URL schemaURL, Class... classesToBeBound)
            throws JAXBException, SAXException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.StringReader;

import java.net.URL;

public class Main {
    public static Object unmarshall(String xml, URL schemaURL, Class... classesToBeBound)
            throws JAXBException, SAXException {

        JAXBContext context = JAXBContext.newInstance(classesToBeBound);

        Unmarshaller unmarshaller = context.createUnmarshaller();

        if (schemaURL != null) {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(schemaURL);
            unmarshaller.setSchema(schema);
        }/*from   www.  jav a  2 s .  c om*/

        StringReader reader = new StringReader(xml);

        return unmarshaller.unmarshal(reader);
    }
}

Related

  1. unmarshall(JAXBContext c, Element e)
  2. unmarshall(String cntxtPkg, InputStream in)
  3. unmarshall(String file, Class desiredClass, Class context)
  4. unmarshall(String xml, Class... classesToBeBound)
  5. unmarshall(String xml, Class clazz)
  6. unmarshaller(Class entityType, InputStream in)
  7. unmarshaller(String xml, Class T)
  8. unmarshallJAXBElement(JAXBElement v)
  9. unMarshallRequest(String xmlString)