我正在尝试对在线模式验证一些xml数据。
$ xmllint --schema https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd --noout iati-data/*.xml
的回报:
warning: failed to load external entity "https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd"
Schemas parser error : Failed to locate the main schema resource at 'https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd'.
WXS schema https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd failed to compile
但是,xsd确实存在:
curl https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd
返回<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.01">
<xsd:annotation>
<xsd:documentation xml:lang="en">
International Aid Transparency Initiative: Activity-Information Schema
Release 2.01, 2014-10-21
etc...
不知道我做错了什么…
不幸的是,XSD是使用支持XSD的相对路径编写的。在评论中甚至有这样的注释:
NOTE: the xml.xsd and iati-common.xsd schemas must be in the same directory as this one.
如果不能更改XSD以引用包含的和导入的XSD的完整的绝对URL,那么一种解决方法是下载主XSD及其依赖项,并访问本地主XSD。另一个解决方法是使用XML Catalog以绝对URL形式重新映射依赖的xsd的位置。