I am trying to perform XML validation. I am provided with a list of diagrams at runtime (possibly wrapped in a jar). Validation fails or fails based on the order in which I provide the schemas in SchemaFactory.
That's what I'm doing:
private void validateXml(String xml, List<URI> schemas){ Source[] source = new StreamSource[schemas.size()]; int i=0; for (URI f : schemas){ source[i++] = new StreamSource(f.openStream()); } SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NA_URI); sf.setResourceResolver(new MyClassPathResourceResolver()); Schema schema = schemaFactory.newSchema(source); Validator validator = schema.newValidator(); validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes()));
again, this fails if the transferred set of schemas does not start with the schema to which the xml referrs root element belongs. Is there a fix for this, or am I doing something wrong?
source share