我正在尝试针对许多不同的模式验证 XML 文件(为人为的示例道歉):
- a.xsd
- b.xsd
- c.xsd
c.xsd 特别是导入 b.xsd 和 b.xsd 导入 a.xsd,使用:
<xs:include schemaLocation="b.xsd"/>
我正在尝试通过 Xerces 以下列方式执行此操作:
XMLSchemaFactory xmlSchemaFactory = new XMLSchemaFactory();
Schema schema = xmlSchemaFactory.newSchema(new StreamSource[] { new StreamSource(this.getClass().getResourceAsStream("a.xsd"), "a.xsd"),
new StreamSource(this.getClass().getResourceAsStream("b.xsd"), "b.xsd"),
new StreamSource(this.getClass().getResourceAsStream("c.xsd"), "c.xsd")});
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlContent)));
但这无法正确导入所有三个模式,导致无法将名称“blah”解析为(n)“组”组件。
我已经使用Python成功验证了这一点,但在Java 6.0和Xerces 2.8.1方面存在实际问题。任何人都可以建议这里出了什么问题,或者更简单的方法来验证我的 XML 文档吗?