Search in sources :

Example 1 with DocumentContainer

use of nl.nn.adapterframework.align.content.DocumentContainer in project iaf by ibissource.

the class XmlTo method translate.

public static void translate(String xml, URL schemaURL, DocumentContainer documentContainer) throws SAXException, IOException {
    // create the ValidatorHandler
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(schemaURL);
    ValidatorHandler validatorHandler = schema.newValidatorHandler();
    // create the parser, setup the chain
    XMLReader parser = new SAXParser();
    XmlAligner aligner = new XmlAligner(validatorHandler);
    XmlTo<DocumentContainer> xml2object = new XmlTo<DocumentContainer>(aligner, documentContainer);
    parser.setContentHandler(validatorHandler);
    aligner.setContentHandler(xml2object);
    // start translating
    InputSource is = new InputSource(new StringReader(xml));
    parser.parse(is);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DocumentContainer(nl.nn.adapterframework.align.content.DocumentContainer) InputSource(org.xml.sax.InputSource) ValidatorHandler(javax.xml.validation.ValidatorHandler) Schema(javax.xml.validation.Schema) StringReader(java.io.StringReader) SAXParser(org.apache.xerces.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader)

Aggregations

StringReader (java.io.StringReader)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 ValidatorHandler (javax.xml.validation.ValidatorHandler)1 DocumentContainer (nl.nn.adapterframework.align.content.DocumentContainer)1 SAXParser (org.apache.xerces.parsers.SAXParser)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1