package pt.utl.ist.sotis.conversion; import java.io.StringReader; 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 org.xml.sax.SAXException; import pt.utl.ist.sotis.bibtex.Items; public class SotisUnmarshaller { public static Items parse(String xml) throws ConversionException { try { JAXBContext jc = JAXBContext.newInstance("pt.utl.ist.sotis.bibtex"); Unmarshaller unmarshaller = jc.createUnmarshaller(); Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema( SotisUnmarshaller.class.getResource("/sotis.xsd")); unmarshaller.setSchema(schema); return (Items) unmarshaller.unmarshal(new StringReader(xml)); } catch (JAXBException e) { throw new ConversionException(e); } catch (SAXException e) { throw new ConversionException(e); } } }