Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can you use xmllint to validate against an internally specified xsd?

I know you can use the xmllint command to validate against local xsd files, or against xsd network file locations, but what I'd like to do is instruct xmllint to validate an XML file against its "internally specified" xsd, for instance this XML specifies an XSD location:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ord-archive:XXX xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                    xsi:schemaLocation="http://somewhere/something.xsd">
 ...

Is there any way to use xmllint and specify to "validate" against its internally specified schemaLocation?

like image 431
rogerdpack Avatar asked Jun 14 '17 22:06

rogerdpack


Video Answer


1 Answers

xsi:schemaLocation should contain a list of URIs, semantically grouped two by two. Each URI appearing at an odd position specifies a namespace, and the URI appearing at the next even position specifies the location hint of the schema to use for this namespace. Location hints may be local or remote.

This is an example with three namespaces:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ord-archive:XXX
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

    xmlns:ord-archive="http://www.example.com/namespace" 
    xmlns:prefix="http://www.example.com/another-namespace" 
    xmlns:other-prefix="http://www.example.com/and-another-namespace" 

    xsi:schemaLocation="
      http://www.example.com/namespace
      http://somewhere.example.com/something.xsd
      http://www.example.com/another-namespace
      some-relative-path-to-a-directory/some-local-file.xsd
      http://www.example.com/and-another-namespace
      file:///some-absolute-path-to-a-directory/some-local-file.xsd">

   <!-- the document itself, which contains elements in the three
        namespaces, referenced with the bound prefixes. -->
</ord-archive:XXX>

The XML Schema specification leaves some degree of freedom to validation engines, so in theory they may or may not follow the hints, they may use cached versions for some namespaces, etc. However, in practice, most validation engines will use your hints or provide an implementation-specific way of controlling their behavior.

The example given under the link in the question uses xsi:noNamespaceSchemaLocation, which contains a location hint for a schema with no target namespace.

like image 190
Ghislain Fourny Avatar answered Oct 12 '22 14:10

Ghislain Fourny