Hi all,
I have a schema file(A1.xsd, ns="http://www.example.org/A") that imports another schema (B.xsd, ns="http://www.example.org/B"). This second schema imports another schema file that has the same target namespace as A1 - A.xsd, ns="http://www.example.org/A".
After loading an XSDSchema instance for A1.xsd, the validation returns an error saying that "Type reference 'http://www.example.org/A#A_ST_01' is unresolved".
Do I have to do something with the imports before invoking the schema validation?
10x
Tsvetan
Source code:
A1.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/A" xmlns:tns="http://www.example.org/A" elementFormDefault="qualified" xmlns:b="http://www.example.org/B">
<import namespace="http://www.example.org/B" schemaLocation="B.xsd"></import>
<complexType name="C_CT_02">
<sequence>
<element name="e1" type="tns:A_ST_01"></element>
<element name="e2" type="tns:A_ST_01NOTEXISTING" nillable="false"></element>
</sequence>
</complexType>
</schema>
B.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/B" xmlns:tns="http://www.example.org/B" elementFormDefault="qualified" xmlns:a="http://www.example.org/A">
<import schemaLocation="A.xsd" namespace="http://www.example.org/A"></import>
<complexType name="B_CT_01"></complexType>
<simpleType name="B_ST_01">
<restriction base="string"/>
</simpleType>
<element name="B_E_01" type="string"/>
<element name="B_E_02" type="tns:B_CT_01"/>
<element name="B_E_03" type="a:A_ST_01"/>
<element name="B_E_04" type="a:A_CT_01"/>
</schema>
A.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/A" xmlns:tns="http://www.example.org/A" elementFormDefault="qualified">
<complexType name="A_CT_01"></complexType>
<simpleType name="A_ST_01">
<restriction base="string"/>
</simpleType>
<element name="A_E_01" type="string"></element>
<element name="A_E_02" type="tns:A_CT_01"></element>
</schema>
Java
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_LOCATION, Boolean.TRUE);
URL entry = Activator.getDefault().getBundle().getResource("resources/original/A1.xsd");
URI uri = URI.createURI(entry.toString());
XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(uri, true);
XSDSchema schema = xsdResource.getSchema();
schema.validate();
EList<XSDDiagnostic> allDiagnostics = schema.getAllDiagnostics();
for (XSDDiagnostic diagnostic : allDiagnostics) {
System.out.println(diagnostic.getLine() + ":" + diagnostic.getMessage());
}