2014-11-03 53 views
1

我使用這個[1] XML模式來驗證與xmllint一個XML文檔:metadata.xml中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. 

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

回答

0

你提到的[2]是有效的,所以錯誤消息表示在當地設置有問題的文件。我猜想,xmllint不符合你從第55行引用的模式位置提示,所以它不會提取Premis模式,然後也找不到提及的類型。

要測試這一點,請嘗試製作一個簡單的模式文檔,導入要使用的everthing並使用它進行驗證。您的文檔使用大都會和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

+0

這驗證示例文檔路易斯2-0.xml驗證,但我在我的文檔中獲得新的錯誤。你的回答指向了正確的方向。謝謝! – Steffen 2014-11-04 06:43:34

+0

@ c-m-sperberg-mcqueen一次後續行動(不值得在SO上提出新的問題)。我認爲在louis-2-0.xml第6行中的命名空間聲明是多餘的。對? – Steffen 2014-11-05 08:41:39

+1

它似乎在最外層的元素上覆制了一個名稱空間聲明:mets元素,是的。 – 2014-11-05 16:31:45