use of javax.xml.transform.dom.DOMSource in project ORCID-Source by ORCID.
the class ValidateV2_1IdentifiersTest method marshallToDOM.
/** Marshals to a DOM
*
* @param type
* @param obj
* @return
*/
private Source marshallToDOM(Class<?> type, Object obj) throws JAXBException, ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
JAXBContext context = JAXBContext.newInstance(type);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(obj, document);
DOMSource source = new DOMSource(document);
return source;
}
use of javax.xml.transform.dom.DOMSource in project ORCID-Source by ORCID.
the class ValidateV2RC3Identifiers method marshallToDOM.
/** Marshals to a DOM
*
* @param type
* @param obj
* @return
*/
private Source marshallToDOM(Class<?> type, Object obj) throws JAXBException, ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
JAXBContext context = JAXBContext.newInstance(type);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(obj, document);
DOMSource source = new DOMSource(document);
return source;
}
use of javax.xml.transform.dom.DOMSource in project ORCID-Source by ORCID.
the class ValidateV2IdentifiersTest method marshallToDOM.
/** Marshals to a DOM
*
* @param type
* @param obj
* @return
*/
private Source marshallToDOM(Class<?> type, Object obj) throws JAXBException, ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
JAXBContext context = JAXBContext.newInstance(type);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(obj, document);
DOMSource source = new DOMSource(document);
return source;
}
use of javax.xml.transform.dom.DOMSource in project OpenClinica by OpenClinica.
the class XmlSchemaValidationHelper method validateAgainstSchema.
public void validateAgainstSchema(File xmlFile, InputStream xsdFile) {
try {
// parse an XML document into a DOM tree
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder parser = builderFactory.newDocumentBuilder();
// parser.isNamespaceAware();
Document document = parser.parse(xmlFile);
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(xsdFile);
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an
// instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException("File was not found", ex.getCause());
} catch (IOException ioe) {
throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
} catch (SAXParseException spe) {
//spe.printStackTrace();
throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
} catch (SAXException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ParserConfigurationException pce) {
throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
}
}
use of javax.xml.transform.dom.DOMSource in project OpenClinica by OpenClinica.
the class XmlSchemaValidationHelper method validateAgainstSchema.
public void validateAgainstSchema(String xml, File xsdFile) {
try {
// parse an XML document into a DOM tree
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder parser = builderFactory.newDocumentBuilder();
Document document = parser.parse(xml);
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(xsdFile);
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an
// instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException("File was not found", ex.getCause());
} catch (IOException ioe) {
throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
} catch (SAXParseException spe) {
//spe.printStackTrace();
throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
} catch (SAXException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ParserConfigurationException pce) {
throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
}
}
Aggregations