使用 xmllint 针对远程文件验证 xml
Using xmllint to validate xml against a remote file
我正在尝试根据在线模式验证一些 xml 数据。
$ xmllint --schema https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd --noout iati-data/*.xml
Returns:
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
Returns
<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...
不确定我做错了什么...
不幸的是 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 及其依赖项并访问本地 main XSD。另一种解决方法是使用 XML Catalog 以绝对 URL 术语重新映射从属 XSD 的位置。
我正在尝试根据在线模式验证一些 xml 数据。
$ xmllint --schema https://raw.githubusercontent.com/IATI/IATI-Schemas/version-2.01/iati-activities-schema.xsd --noout iati-data/*.xml
Returns:
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
Returns
<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...
不确定我做错了什么...
不幸的是 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 及其依赖项并访问本地 main XSD。另一种解决方法是使用 XML Catalog 以绝对 URL 术语重新映射从属 XSD 的位置。