title: xmllint : validate an XML file against two XSD schemas (envelope / payload)
body: <p>I am using <a href="http://xmlsoft.org/xmllint.html" rel="noreferrer">xmllint</a> to do some validations and I have an XML instance document which needs to validate against two schemas: one for the outer "envelope" (which includes an <strong>any</strong> element) and one for the particular payload. Say <strong>A.xsd</strong> is the envelope schema, <strong>B.xsd</strong> a payload schema (there are different possible payloads) and <strong>ab.xml</strong> a valid XML instance document (I provide an example at the end of the post).</p>
  
  <p>I have all three files locally available in the same directory and am using <a href="http://xmlsoft.org/xmllint.html" rel="noreferrer">xmllint</a> to perform the validation, providing as the <em>schema</em> argument the location of the outer (envelope) schema:</p>
  
  <pre><code>xmllint -schema A.xsd ab.xml
  </code></pre>
  
  <p>... yet, although I provide the location of both A.xsd and B.xsd in the instance document (using the <strong>xsi:schemaLocation</strong> element) <strong>xmllint</strong> fails to find it and complains:</p>
  
  <pre><code>ab.xml:8: element person: Schemas validity error : Element '{http://www.example.org/B}person': No matching global element declaration available, but demanded by the strict wildcard.
  ab.xml fails to validate
  </code></pre>
  
  <p>So apparently <strong>xmllint</strong> is not reading the <strong>xsi:schemaLocation</strong> element. I understand that <strong>xmllint</strong> can be configured with catalogs but I failed to get <strong>xmllint</strong> to find both schemas. How should I get <strong>xmllint</strong> to take into account both schemas when validating the instance document or is there another command line utility or graphical tool I could use instead?</p>
  
  <h1>SSCCE</h1>
  
  <h2>A.xsd - envelope schema</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;schema elementFormDefault="qualified" 
          xmlns               ="http://www.w3.org/2001/XMLSchema"
          xmlns:a             ="http://www.example.org/A"
          targetNamespace ="http://www.example.org/A"&gt;
  
         &lt;element name="someType" type="a:SomeType"&gt;&lt;/element&gt;
  
          &lt;complexType name="SomeType"&gt;
              &lt;sequence&gt;
                  &lt;any namespace="##other" processContents="strict"/&gt;
              &lt;/sequence&gt;
          &lt;/complexType&gt;
  &lt;/schema&gt;
  </code></pre>
  
  <h2>B.xsd - payload schema</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;schema elementFormDefault="qualified"
      xmlns          ="http://www.w3.org/2001/XMLSchema"
      xmlns:b        ="http://www.example.org/B"
      targetNamespace="http://www.example.org/B"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  
      &lt;element name="person" type="b:PersonType"&gt;&lt;/element&gt;
      &lt;complexType name="PersonType"&gt;
          &lt;sequence&gt;
                  &lt;element name="firstName" type="string"/&gt;
                  &lt;element name="lastName"  type="string"/&gt;
          &lt;/sequence&gt;
      &lt;/complexType&gt;
    &lt;/schema&gt;
  </code></pre>
  
  <h2> ab.xml - instance document </h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
              &lt;b:person&gt;
                  &lt;b:firstName&gt;Mary&lt;/b:firstName&gt;
                  &lt;b:lastName&gt;Bones&lt;/b:lastName&gt;
              &lt;/b:person&gt;
  
  &lt;/a:someType&gt;
  </code></pre>