I have two .xsd
files in the same src/main/resource
folder:
- outer.xsd
- inner.xsd
outer.xsd
looks like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://project.domain.com/model"
targetNamespace="http://project.domain.com/model"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="inner.xsd"/>
<xs:element name="innerObject" type="tns:InnerObjectType"/>
</xs:schema>
and inner.xsd
looks like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:model="http://project.domain.com/model"
targetNamespace="http://project.domain.com/model"
elementFormDefault="qualified" attributeFormDefault="qualified" version="1.0">
<xs:complexType name="InnerObjectType">
<xs:sequence>
<xs:element name="property1" type="xs:string"/>
<xs:element name="property2" type="xs:string"/>
</xs:sequence>
<xs:complexType>
</xs:schema>
Now, in another project, I'm using outer.xsd
to validate input XML files like so:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
ClassLoader classLoader = objectType.getClassLoader();
InputStream stream = classLoader.getResourceAsStream(schemaPath);
Source schemaSource = new StreamSource(stream);
Schema schema = factory.newSchema(schemaSource);
...
} catch (SAXException exception) {...}
On the line where I call newSchema
, I am getting the following exception:
src-resolve: Cannot resolve the name 'tns:InnerObjectType' to a(n) 'type definition' component.
It appears that this code is able to find the outer schema by path, but during the process of resolving the inner type, it cannot find the inner schema.
Anybody have a suggestion of how I can get it to resolve that inner type?
Note: I was able to use outer.xsd
to generate an XML file in eclipse, so I am relatively certain that the structure of the .xsd
files is correct ... it's just that whatever the context is when outer.xsd
is being resolved doesn't have access to inner.xsd
.
A parallel question is: How can I find out what the context is in which the type is being resolved? (ie ... where is it looking for inner.xsd
?)