Hello,

I want to validate an XML document agains multiple XML schemas with different namespaces. For example, I have the following XML document:

book.xml
<?xml version="1.0"?>
<Book xmlns="http://www.book.org"
xmlns:ch1="http://www.chapter1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.book.org book.xsd">
<Chapters>
<ch1:Paragraph1>This is the paragraph1</ch1:Paragraph1>
</Chapters>
</Book>


and the follwong XML schemas:
book.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ch1="http://www.chapter1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.book.org" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.chapter1" />
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element name="Chapters">
<xs:complexType>
<xs:sequence>
<xs:element ref="ch1:Paragraph1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


book1.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://www.chapter1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.chapter1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Paragraph1" type="xs:string" />
</xs:schema>


I want to validate the book.xml using SAX API. I am using the following code:

package saxxercesmultiplevalidation;

import org.xml.sax.*;
import java.io.*;
import javax.xml.transform.stream.*;
import javax.xml.validation.*;
import javax.xml.XMLConstants;
import javax.xml.parsers.*;


import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;


public class SAXXercesMultipleValidator extends DefaultHandler {

public static void main(String[] args)
{
try {
FileInputStream is = new FileInputStream("book.xml");

StreamSource[] sources = new StreamSource[2];
FileInputStream ss = new FileInputStream("book.xsd");
sources[0] = new StreamSource(ss);
ss = new FileInputStream("book1.xsd");
sources[1] = new StreamSource(ss);

SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCH EMA_NS_URI);
Schema schema = schemaFactory.newSchema(sources);

SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(true);
saxFactory.setValidating(false);
saxFactory.setXIncludeAware(true);
saxFactory.setSchema(schema);

SAXParser parser = saxFactory.newSAXParser();
parser.parse(is, new SAXXercesMultipleValidator());
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (SAXException e) {
e.printStackTrace();
}
catch (ParserConfigurationException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}


public void warning(SAXParseException e) throws SAXException
{
System.err.println("SAX Warning: " + e.getLocalizedMessage());
}

public void error(SAXParseException e) throws SAXException
{
System.err.println("SAX Error: " + e.getLocalizedMessage());
}


public void fatalError(SAXParseException e) throws SAXException
{
System.err.println("SAX Fatal Error: " + e.getLocalizedMessage());
}

}


And I get the following error when I run the project:
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'ch1:Paragraph1' to a(n) 'element declaration' component.


It seems that the parser cannot recognize the paragraph1 element that belongs to a different namespace.
Can anyone help me?

Thank you in advance.