I am trying to unmarshal a XML file using EclipseLink MOXy 2.6 against multiple XML schemas - common.xsd
and userOfCommon.xsd
.
userOfCommon.xsd
includes common.xsd
and uses certain types defined in it.
I you want validation you have to set the unmarshaller like this:
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source common = new StreamSource(this.getClass().getResourceAsStream("xsd/common.xsd"));
Source userOfCommon = new StreamSource(this.getClass().getResourceAsStream("xsd/userOfCommon.xsd"));
Schema schema = sf.newSchema(new Source[] {common, userOfCommon});
unmarshaller.setSchema(sf.newSchema(schema));
But setting the schema gives an error saying "Failing to resolve the 'Some ComplexType Name' to a(n) 'type definition' component."
I tried to set the schema as a file name like this
Schema schema = sf.newSchema(new File("xsd/userOfCommon.xsd"));
And it works. But I want to set the schema as Source items in order for it to be loaded from the classpath.
Any suggestions how to achieve this?