I would like to call an Open Journey Planner webservice and validate my requests I use for this. Unfortunately, I'm not able to load the XSD properly. My (simplified) code so far:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new URL("https://raw.githubusercontent.com/VDVde/OJP/master/OJP_Requests.xsd"));
schema.newValidator().validate(...);
However, I get the following error already when creating the schema: org.xml.sax.SAXParseException; systemId: https://raw.githubusercontent.com/VDVde/OJP/master/OJP_Common.xsd; lineNumber: 58; columnNumber: 66; src-resolve: Cannot resolve the name 'siri:OperatorRefStructure' to a(n) 'type definition' component.
Please note, that the error is only in OJP_Common.xsd and I'm loading OJP_Requests.xsd. This OJP_Common.xsd is referenced in the request <xs:include schemaLocation="OJP_Common.xsd"/> (via OJP_Fare.xsd). The missing siri:OperatorRefStructure however is only referenced via an <xs:import namespace="http://www.siri.org.uk/siri" schemaLocation="./siri_model/siri_operator_support-v2.0.xsd"/>.
I guess (and also partially confirmed this by debugging) only "includes" are read automatically and "imports" are not. How to change this so that I can load the whole XSD and so use it for validation?
Edit, minimal XSD leading to this error:
OJP_Requests.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:siri="http://www.siri.org.uk/siri" targetNamespace="http://www.vdv.de/ojp">
<xs:import namespace="http://www.siri.org.uk/siri" schemaLocation="./siri_model/siri_modes-v1.1.xsd"/>
<xs:import namespace="http://www.siri.org.uk/siri" schemaLocation="./siri_model/siri_operator_support-v2.0.xsd"/>
<xs:element name="OperatorRef" type="siri:OperatorRefStructure"/>
</xs:schema>
siri_model/siri_modes-v1.1.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.siri.org.uk/siri"/>
siri_model/siri_operator_support-v2.0.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.siri.org.uk/siri">
<xsd:complexType name="OperatorRefStructure"/>
</xsd:schema>
Interestingly, when I switch the order of the two imports in OJP_Requests.xsd, this minimal example is working. Unfortunately, the actual XSD structure is much larger and not under my control.