xmllint : validate an XML file against two XSD schemas (envelope / payload) xmllint : validate an XML file against two XSD schemas (envelope / payload) xml xml

xmllint : validate an XML file against two XSD schemas (envelope / payload)


You can create a wrapper schema and import both namespaces.AB.xsd:

<?xml version="1.0" encoding="UTF-8"?><schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema">    <import namespace="http://www.example.org/A" schemaLocation="A.xsd"/>    <import namespace="http://www.example.org/B" schemaLocation="B.xsd"/></schema>

Then:

xmllint --schema AB.xsd ab.xml<?xml version="1.0" encoding="UTF-8"?><a:someType xmlns:a="http://www.example.org/A" xmlns:b="http://www.example.org/B" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/A A.xsd                             http://www.example.org/B B.xsd">            <b:person>                <b:firstName>Mary</b:firstName>                <b:lastName>Bones</b:lastName>            </b:person></a:someType>ab.xml validates


I quit on xmllint and used Xerces instead.

I downloaded Xerces tarball and after exploding it to some local folder I created the following validate script based on this suggestion (from web archive - original link being now dead):

#!/bin/bashXERCES_HOME=~/software-downloads/xerces-2_11_0/echo $XERCES_HOMEjava -classpath $XERCES_HOME/xercesImpl.jar:$XERCES_HOME/xml-apis.jar:$XERCES_HOME/xercesSamples.jar sax.Counter $*

The ab.xml file is then validated, against both schemas, with the following command:

 validate -v -n -np -s -f ab.xml

Xerces is reading the schema locations from the xsi:schemaLocation element in ab.xml so they don't need to be provided in the command line invocation.


If you had an import element in your A.xsd, right after opening the schema tag,

<xsd:import namespace="http://www.example.org/B" schemaLocation="B.xsd"/>

then you could pass A.xsd to xmllint and it would work with:

xmllint -schema A.xsd ab.xml