Skip to main content

SchemaFactory - Problem with compiling multiple schemas in same namespace

6 replies [Last post]
Joined: 2007-06-05

Till now, I have been able to use the SchemaFactory to validate a single schema file against xml source. No problems.

Now, I have a new schema that is actually broken up into a number of schemas. All belong to same namespace and the main schema "includes" all the others.

So, I have "main.xsd" that inturn includes "1.xsd", ...... "n.xsd".

I tried
1) factory.newSchema(new StreamSource(...."main.xsd"));
2) factory.newSchema(sources); // sources is an array of Source

All of them fail with the dreaded
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'someElement' to a(n) 'element declaration' component.

If I were to append all my xsd into main.xsd it works just fine.

The xsd:include tags within main.xsd refers to all the other xsds with just the relevant name. No relative paths or anything like that.

Does anyone have a suggestion/solution to this problem? Any pointers are much appreciated.

I have seen a similar bug at
but no workaround. Is it still an issue or has anyone been able to get around this problem by custom coding LSResourceResolver?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-05-05

Hello chaganthi,

I'm facing to the same problem you described... At this time I don't still know how to implement the 'LSResourceResolver'.

Could you provide us a snippet of your code ?

Thanks in advance,


Joined: 2009-10-08

Here's a code example that shows how to load imported xsd schemas from the classpath:


private Schema createSchema(String schemName)
throws IOException, SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException {
// create a SchemaFactory
SchemaFactory factory = SchemaFactory.newInstance("");
[b]factory.setResourceResolver(new ClasspathResourceResolver());[/b]

// locate the schema on the classpath
InputStream schemaStream = getClass().getResourceAsStream("/" + schemName);
if (schemaStream == null) {
throw new IOException("XML schema not found on classpath: " + schemName);

return factory.newSchema(new StreamSource(schemaStream));

* This is an implementation of LSResourceResolver that can resolve XML schemas from the classpath
[b]private class ClasspathResourceResolver implements LSResourceResolver[/b] {
private DOMImplementationLS domImplementationLS;

private ClasspathResourceResolver() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
domImplementationLS = (DOMImplementationLS) registry.getDOMImplementation("LS");

public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId,
String baseURI) {
"==== Resolving '" + type + "' '" + namespaceURI + "' '" + publicId + "' '" + systemId + "' '" +
baseURI + "'");

LSInput lsInput = domImplementationLS.createLSInput();
InputStream is = getClass().getResourceAsStream("/" + systemId);
return lsInput;

Joined: 2007-06-05

I am answering this myself.

Implementing a custom LSResourceResolver and supplying schemas to SchemaFactory via a Source[] did the trick.

All xsds have been jarred with a custom manifest (that had class-path entries) and that jar has been placed in the WEB-INF/lib folder.

Hopefully it will help others that might run into this issue.


Joined: 2007-06-26

I have the same problem.
How do implement the LSresolver?

could you give an example..

Joined: 2005-05-05

Actually facing also this problem... Any example on how to implement this famous 'LSResourceResolver' interface ??

Thanks in advance,


Joined: 2007-06-05

Other interesting observations.

If I were to have all my xsds in %JBoss_Home%\bin directory, there are no problems.I would not want that to be my solution for obvious reasons. The schema gets compiled and validated.

I tried jarring all the xsds with a class-path manifest and using that jar. Did not work.

Tried having all xsds within my web-inf/classes directory, that did not work either.