title: One xml namespace equals one and only one schema file?
body: <p>...or <strong>Why do these files validate in <em>Visual Studio 2010</em> but not with <em>xmllint</em><sup>1</sup>?</strong></p>
  
  <p>I'm currently working against a published xml schema where the original author's habit is to break down the schemas into several .xsd-files, but where some schema files have the same <code>targetNamespace</code>. Is this really "allowed"?</p>
  
  <p>Example (extremely simplified):</p>
  
  <pre><code>File    targetNamespace    Contents
  ------------------------------------------------------------
  b1.xsd  uri:tempuri.org:b  complex type "fooType"
  b2.xsd  uri:tempuri.org:b  simple type "barType"
  
  a.xsd   uri:tempuri.org:a  imports b1.xsd and b2.xsd
                             definition of root element "foo", that
                             extends "b:fooType" with an attribute
                             of "b:barType"
  </code></pre>
  
  <p><em>(Complete file contents below.)</em></p>
  
  <p>Then I have an xml file, <code>data.xml</code>, with this content:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;foo bar="1" xmlns="uri:tempuri.org:a" xmlns:xs="http://www.w3.org/2001/XMLSchema" /&gt;
  </code></pre>
  
  <p>For a long time, I have believed that all of this was correct, since Visual Studio apparently allows this schema style. However, today I decided to set up a command line utility for validating xml files, and I chose <code>xmllint</code>.</p>
  
  <p>When I ran <code>xmllint --schema a.xsd data.xml</code>, I was presented with this warning:</p>
  
  <blockquote>
    <p>a.xsd:4: element import: Schemas parser warning : Element '{<a href="http://www.w3.org/2001/XMLSchema" rel="noreferrer">http://www.w3.org/2001/XMLSchema</a>}import':
    Skipping import of schema located at 'b2.xsd' for the namespace 'uri:tempuri.org:b', since this
    namespace was already imported with the schema located at 'b1.xsd'.</p>
  </blockquote>
  
  <p>The fact that the import of <code>b2.xsd</code> was skipped obviously leads to this error:</p>
  
  <blockquote>
    <p>a.xsd:9: element attribute: Schemas parser error : attribute decl. 'bar', attribute 'type':
    The QName value '{uri:tempuri.org:b}barType' does not resolve to a(n) simple type definition.</p>
  </blockquote>
  
  <p>If <code>xmllint</code> is correct, there would be an error in the published specs I'm working against. <em>Is there?</em> And Visual Studio would be wrong. <em>Is it?</em></p>
  
  <p>I do realize the difference between <code>xs:import</code> and <code>xs:include</code>. Right now, I just don't see how <code>xs:include</code> could fix things, since:</p>
  
  <ul>
  <li><code>b1.xsd</code> and <code>b2.xsd</code> have the same <code>targetNamespace</code></li>
  <li>they both differ in <code>targetNamespace</code> from <code>a.xsd</code></li>
  <li>and they do not (need to) know about each other</li>
  </ul>
  
  <p>Is this a flaw in the original schema specification? I'm beginning to think that the third bullet point is crucial. Should the fact that they don't know about each other have led to placing them in different namespaces to begin with?</p>
  
  <hr>
  
  <p>b1.xsd:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema targetNamespace="uri:tempuri.org:b" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:complexType name="fooType" /&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>b2.xsd:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema targetNamespace="uri:tempuri.org:b" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:simpleType name="barType"&gt;
      &lt;xs:restriction base="xs:integer" /&gt;
    &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>a.xsd:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema targetNamespace="uri:tempuri.org:a" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:b="uri:tempuri.org:b"&gt;
    &lt;xs:import namespace="uri:tempuri.org:b" schemaLocation="b1.xsd" /&gt;
    &lt;xs:import namespace="uri:tempuri.org:b" schemaLocation="b2.xsd" /&gt;
    &lt;xs:element name="foo"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:complexContent&gt;
          &lt;xs:extension base="b:fooType"&gt;
            &lt;xs:attribute name="bar" type="b:barType" /&gt;
          &lt;/xs:extension&gt;
        &lt;/xs:complexContent&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <hr>
  
  <p><strong><em>Notes:</em></strong></p>
  
  <p><sup>1)</sup> I'm using the Windows port of <a href="http://xmlsoft.org/" rel="noreferrer">libxml2/xmllint</a> found at <a href="http://www.zlatkovic.com/libxml.en.html" rel="noreferrer">www.zlatkovic.com</a>.</p>