2

我正在使用schemavalidateAnt 的任务来验证 XML 文档。

<schemavalidate
    noNamespaceFile="${user.input.xsd}" file="${user.input.xml}">
</schemavalidate>

这按预期工作。但现在我有使用 XInclude 的架构文件,如下所示:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="..." xpointer="xmlns(xs=http://www.w3.org/2001/XMLSchema)xpointer(/xs:schema/xs:*)"/>
</xs:schema>

这在 Ant 中给出了以下错误:

foo.xsd:8:136: s4s-elt-schema-ns: 元素“include”的命名空间必须来自模式命名空间“ http://www.w3.org/2001/XMLSchema ”。

现在我尝试通过启用相应的功能来启用 XInclude 处理:

<schemavalidate
    noNamespaceFile="${user.input.xsd}" file="${user.input.xml}">
  <attribute name="http://apache.org/xml/features/xinclude" value="true"/>
</schemavalidate>

但这无济于事,错误消息保持不变。该功能似乎被解析器识别,因为当我更改属性元素以使用一些不存在的功能时,我收到相应的错误消息,例如

解析器 org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser 无法识别功能http://apache.org/xml/features/xinclud

是否可以在此处启用 XInclude 处理?

编辑 1

启用 Ant 调试模式时,我可以看到该功能设置正确:

[schemavalidate] Using SAX2 reader org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser
[schemavalidate] Setting feature http://xml.org/sax/features/validation=true
[schemavalidate] Setting feature http://apache.org/xml/features/xinclude=true
[schemavalidate] Setting feature http://xml.org/sax/features/namespaces=true
[schemavalidate] Setting feature http://apache.org/xml/features/validation/schema=true
[schemavalidate] Setting feature http://apache.org/xml/features/validation/schema-full-checking=true
[schemavalidate] Validating foo.xml...
4

0 回答 0