使用xmllint对远程文件验证xml

时间:2015-10-15 13:55:21

标签: xml xsd-validation xmllint

我正在尝试针对在线架构验证一些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...

不确定我做错了什么......

1 个答案:

答案 0 :(得分:1)

不幸的是that 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的位置。