Я использую Java 5 javax.xml.validation.Validator для проверки файла XML. Я сделал это для одной схемы, которая использует только импорт, и все работает нормально. Теперь я пытаюсь проверить с помощью другой схемы, использующей импорт, и один из них. У меня проблема в том, что элемент в основной схеме игнорируется, подтверждение говорит, что не может найти свое объявление.
Вот как я строю схему:
InputStream includeInputStream = getClass().getClassLoader().getResource("include.xsd").openStream();
InputStream importInputStream = getClass().getClassLoader().getResource("import.xsd").openStream();
InputStream mainInputStream = getClass().getClassLoader().getResource("main.xsd").openStream();
Source[] sourceSchema = new SAXSource[]{includeInputStream , importInputStream,
mainInputStream };
Schema schema = factory.newSchema(sourceSchema);
Теперь вот выдержка из объявления в main.xsd
<xsd:schema xmlns="http://schema.omg.org/spec/BPMN/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import="http://www.foo.com/import" targetNamespace="http://main/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:import namespace="http://www.foo.com/import" schemaLocation="import.xsd"/>
<xsd:include schemaLocation="include.xsd"/>
<xsd:element name="element" type="tElement"/>
<...>
</xsd:schema>
Если я скопирую код моего включенного XSD в main.xsd, он отлично работает. Если я этого не сделаю, валидация не найдет декларацию "Элемент".