我有两个具有循环依赖关系的模式 A 和 B(这是一个中间步骤)。我用作输入的 XML 文件根据 xmllint 和 Visual Studio 对架构进行验证。Eclipse 告诉我这两个模式都包含两个同名的全局组件。
A.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
targetNamespace="http://foo.org/A"
xmlns="http://foo.org/A"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xs:import schemaLocation="b.xsd" />
B.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
xmlns:foo="http://foo.org/A"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://foo.org/A" schemaLocation="a.xsd" />
我传递给 Unmarshaller 的 XSD 是 A.xsd。当它遇到 B.xsd 中定义的元素时,它会抱怨:
org.xml.sax.SAXParseException:cvc-elt.1:找不到元素“foo”的声明。
我通过(伪)设置了架构:
InputStream in = .. A.xsd
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return factory.newSchema(new StreamSource(in);
谁能解释我做错了什么?谢谢。