use of javax.xml.validation.SchemaFactory in project jangaroo-tools by CoreMedia.
the class ValidateSchemas method validateExmlSchema.
@Test
public void validateExmlSchema() throws IOException, SAXException, URISyntaxException {
String schemaLang = "http://www.w3.org/2001/XMLSchema";
// get validation driver:
SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
// create schema by reading it from an XSD file:
factory.newSchema(new StreamSource(getFile("/net/jangaroo/exml/schemas/exml.xsd")));
}
use of javax.xml.validation.SchemaFactory in project nokogiri by sparklemotion.
the class XmlSchema method getSchema.
private Schema getSchema(Source source, String currentDir, String scriptFileName) throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
SchemaResourceResolver resourceResolver = new SchemaResourceResolver(currentDir, scriptFileName, null);
schemaFactory.setResourceResolver(resourceResolver);
schemaFactory.setErrorHandler(new IgnoreSchemaErrorsErrorHandler());
return schemaFactory.newSchema(source);
}
use of javax.xml.validation.SchemaFactory in project CoreNLP by stanfordnlp.
the class XMLUtils method getValidatingXmlParser.
/**
* Returns a validating XML parser given an XSD (not DTD!).
*
* @param schemaFile File wit hXML schema
* @return An XML parser in the form of a DocumentBuilder
*/
public static DocumentBuilder getValidatingXmlParser(File schemaFile) {
DocumentBuilder db = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(schemaFile);
dbf.setSchema(schema);
db = dbf.newDocumentBuilder();
db.setErrorHandler(new SAXErrorHandler());
} catch (ParserConfigurationException e) {
System.err.printf("%s: Unable to create XML parser\n", XMLUtils.class.getName());
e.printStackTrace();
} catch (SAXException e) {
System.err.printf("%s: XML parsing exception while loading schema %s\n", XMLUtils.class.getName(), schemaFile.getPath());
e.printStackTrace();
} catch (UnsupportedOperationException e) {
System.err.printf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName());
e.printStackTrace();
}
return db;
}
use of javax.xml.validation.SchemaFactory in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method unmarshall.
private Object unmarshall(Reader reader, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try {
JAXBContext context = JAXBContext.newInstance(type);
Unmarshaller unmarshaller = context.createUnmarshaller();
if (schemaPath != null) {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(schemaPath).toURI()));
unmarshaller.setSchema(schema);
}
return unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException("Unable to unmarshall orcid message" + e);
}
}
use of javax.xml.validation.SchemaFactory in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method marshall.
private void marshall(Object object, String path) throws JAXBException, SAXException, URISyntaxException {
JAXBContext context = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = context.createMarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(path).toURI()));
marshaller.setSchema(schema);
marshaller.marshal(object, System.out);
}
Aggregations