XML:缺少类型定义

时间:2014-11-03 10:52:02

标签: xml xsd xmllint

我正在使用这个[1] XML Schema来使用xmllint验证XML文档:

xmllint --noout --schema mets.xsd metadata.xml

验证失败,

metadata.xml:55: element object: Schemas validity error : Element '{info:lc/xmlns/premis-v2}object', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value '{info:lc/xmlns/premis-v2}file' of the xsi:type attribute does not resolve to a type definition. 
metadata.xml:55: element object: Schemas validity error : Element '{info:lc/xmlns/premis-v2}object': The type definition is absent.

metadata.xml中的第55行:

<premis:object xsi:type="premis:file" xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd">

但是,有一个我想要的示例文档。它位于这里[2]。

当我针对模式验证此示例时,会发生相同的验证错误。

louis-2-0.xml:80: element object: Schemas validity error : Element '{info:lc/xmlns/premis-v2}object', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value '{info:lc/xmlns/premis-v2}file' of the xsi:type attribute does not resolve to a type definition.
louis-2-0.xml:80: element object: Schemas validity error : Element '{info:lc/xmlns/premis-v2}object': The type definition is absent.

我错过了什么?

[1] http://www.loc.gov/standards/mets/mets.xsd

[2] http://www.loc.gov/standards/premis/louis-2-0.xml

1 个答案:

答案 0 :(得分:0)

您引用为[2]的文档有效,因此错误消息表明您的本地设置存在问题。我猜xmllint并不尊重你从第55行引用的模式位置提示,所以它没有获取Premis模式,然后找不到提到的类型。

要测试它,请尝试制作一个简单的架构文档,用于导入要使用的内容,并使用它进行验证。您的文档使用Mets和Premis,因此我们将导入这两个模式:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           elementFormDefault="qualified"> 

  <xs:import namespace="http://www.loc.gov/METS/"
     schemaLocation="http://www.loc.gov/standards/mets/mets.xsd"
  />

  <xs:import namespace="info:lc/xmlns/premis-v2"
    schemaLocation=
      "http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd"
  />
</xs:schema>

将其另存为mets-premis.xsd(或您喜欢的任何名称)。

现在尝试使用xmllint --noout --schema mets-premis.xsd metatdata.xml

进行验证
相关问题