use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2RC4Identifiers method validateSampleXML.
public void validateSampleXML(String name) throws SAXException, IOException {
Source source = getInputStream("/record_2.0_rc4/samples/" + name + "-2.0_rc4.xml");
Validator validator = getValidator(name);
validator.validate(source);
}
use of javax.xml.validation.Validator in project opennms by OpenNMS.
the class XmlTest method validateXmlString.
protected void validateXmlString(final String xml) throws Exception {
if (getSchemaFile() == null) {
LOG.warn("skipping validation, schema file not set");
return;
}
final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
final File schemaFile = new File(getSchemaFile());
LOG.debug("Validating using schema file: {}", schemaFile);
final Schema schema = schemaFactory.newSchema(schemaFile);
final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setValidating(true);
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setSchema(schema);
assertTrue("make sure our SAX implementation can validate", saxParserFactory.isValidating());
final Validator validator = schema.newValidator();
final ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
final Source source = new StreamSource(inputStream);
validator.validate(source);
}
use of javax.xml.validation.Validator in project opennms by OpenNMS.
the class JaxbUtilsTest method testMarshalEvent.
@Test
public void testMarshalEvent() throws Exception {
final Event e = getEvent();
final String xml = JaxbUtils.marshal(e);
assertTrue(xml.contains("JaxbUtilsTest"));
LOG.debug("event = {}", e);
LOG.debug("xml = {}", xml);
final StringWriter sw = new StringWriter();
JaxbUtils.marshal(e, sw);
assertEquals(sw.toString(), xml);
final SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
final InputStream is = this.getClass().getResourceAsStream("/xsds/event.xsd");
// if this is null, it's because Eclipse can be confused by "classifier" test dependencies like opennms-model-*-xsds
// it only works if opennms-model is *not* pulled into eclipse (go figure)
Assume.assumeNotNull(is);
LOG.debug("Hooray! We have an XSD!");
final Schema schema = factory.newSchema(new StreamSource(is));
final Validator v = schema.newValidator();
v.validate(new StreamSource(new StringReader(xml)));
}
use of javax.xml.validation.Validator in project wildfly by wildfly.
the class StandardConfigsXMLValidationUnitTestCase method parseXml.
private void parseXml(String xmlName) throws ParserConfigurationException, SAXException, IOException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(new ErrorHandlerImpl());
schemaFactory.setResourceResolver(DEFAULT_RESOURCE_RESOLVER);
Schema schema = schemaFactory.newSchema(SCHEMAS);
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandlerImpl());
validator.setFeature("http://apache.org/xml/features/validation/schema", true);
validator.setResourceResolver(DEFAULT_RESOURCE_RESOLVER);
validator.validate(new StreamSource(getXmlFile(xmlName)));
}
use of javax.xml.validation.Validator in project wildfly by wildfly.
the class XSDValidationUnitTestCase method validateXsd.
private void validateXsd(final File xsdFile) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(xsdFile);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(new ErrorHandlerImpl());
schemaFactory.setResourceResolver(new XMLResourceResolver());
Schema schema = schemaFactory.newSchema(resource("schema/XMLSchema.xsd"));
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
}
Aggregations