I am trying to validate an XML String against two Strings that contains an XSD. One XSD includes the other. I get the error: "Cannot resolve the name 'ServiceSpecificationSchema:ServiceIdentifier' to a(n) 'type definition' component."
It looks like, that my code doesnt recognize the second XSD file. Others solved that problem by using a LSResourceResolver ( seen here: How to validate an XML file using Java with an XSD having an include? )
But in that exampe the files are stored local. Is there a good way, that this method works with my XSD strings?
Any hint would be appreciated.
My code so far:
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); Schema schema = factory.newSchema(new SAXSource[] { (new SAXSource(new InputSource(new StringReader(XSD)))), (new SAXSource(new InputSource(new StringReader(XSD2)))) }); Validator validator = schema.newValidator(); validator.validate(new StreamSource(new StringReader(inputXml)));