I need to XSOM XSD using XSOM , but this XSD contains loop import.
A.xsd
<xs:schema xmlns="ns1" targetNamespace="ns1"> <xs:import namespace="ns2" schemaLocation="B.xsd"/> <xs:element name="MyElement" type="xs:string"/> </xs:schema>
B.xsd
<xs:schema xmlns="ns2" targetNamespace="ns2" xmlns:ns1="ns1"> <xs:import namespace="ns1" schemaLocation="A.xsd"/> <xs:complexType name="MyComplex"> <xs:sequence> <xs:element ref="ns1:MyElement" minOccurs="0"/> <xs:sequence> <xs:complexType> </xs:schema>
XSOM Unable to parse a schema because it detects elements that are already defined due to circular import. So I tried to break down the circular import by displacing the elements defined by A and used in B.
C.xsd contains an element from A that is used by B. Note that these elements are not used in A. Do not ask me why they were defined in A.
<xs:schema xmlns="ns1" targetNamespace="ns1"> <xs:element name="MyElement" type="xs:string"/> </xs:schema>
A.xsd becomes
<xs:schema xmlns="ns1" targetNamespace="ns1"> <xs:import namespace="ns2" schemaLocation="B.xsd"/> </xs:schema>
B.xsd (import C.xsd instead of A.xsd) becomes
<xs:schema xmlns="ns2" targetNamespace="ns2" xmlns:ns1="ns1"> <xs:import namespace="ns1" schemaLocation="C.xsd"/> <xs:complexType name="MyComplex"> <xs:sequence> <xs:element ref="ns1:MyElement" minOccurs="0"/> <xs:sequence> <xs:complexType> </xs:schema>
XSOM can parse XSD. But now I can not create a circuit with the following code:
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setResourceResolver(new MyResourceResolver());
I use the standard implementation bundled with JDK 1.7. I get an exception:
src-resolve: Cannot resolve the name 'ns1:MyElement' to a(n) 'element declaration' component.
The problem is that the resource recognizer is called for namespace B, but not for namespace A, which makes sense. Because the namespace A is shared between A.xsd and C.xsd, the resource recognizer cannot find the elements defined in C.xsd.
Are circular imports valid? Is it possible to split circular imports so that it can be analyzed using XSOM and then loaded using SchemaFactory ?