Search code examples
xmlxsdxmllint

XML: Type definition is absent


I am using this[1] XML Schema to validate a XML document with xmllint:

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

The validation fails with

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.

Line 55 in metadata.xml:

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

However, there is an example document for what I want. It is located here[2].

When I validate this example against the schema, the same validation error occurs.

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.

What am I missing?

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

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


Solution

  • The document you refer to as [2] is valid, so the error messages indicate a problem in your local setup. I'd guess that xmllint is not honoring the schema-location hint you quote from line 55, so it is not fetching the Premis schema and then is not finding the type mentioned.

    To test that, try making a simple schema document that imports everthing you want to use, and use it to validate. Your document uses Mets and Premis, so we'll import those two schemas:

    <?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>
    

    Save this as mets-premis.xsd (or any name you like).

    Now try validating with xmllint --noout --schema mets-premis.xsd metatdata.xml