title: Using XSDs with includes
body: <p>Here is an XSD:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsd:schema 
  elementFormDefault='unqualified' 
  attributeFormDefault='unqualified' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  &gt;
  
    &lt;xsd:simpleType name='TheSimpleType'&gt;
      &lt;xsd:restriction base='xsd:string' /&gt;
    &lt;/xsd:simpleType&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>Here is a second XSD that includes the one above:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;xsd:schema 
  elementFormDefault='unqualified' 
  attributeFormDefault='unqualified' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  targetNamespace='a'
  xmlns='a'
  &gt;
  
    &lt;xsd:include schemaLocation='Include.xsd' /&gt;
  
    &lt;xsd:element name = "TheElement" &gt;
    &lt;xsd:complexType&gt;
    &lt;xsd:attribute name="Code" type="TheSimpleType" use="required"/&gt;
    &lt;/xsd:complexType&gt;
    &lt;/xsd:element&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>I need to read the (second) XSD into C# and:</p>
  
  <ol>
  <li>check that it is a valid XSD, and</li>
  <li>validate documents against it.</li>
  </ol>
  
  <p>Here is some C# to read in the schemata:</p>
  
  <pre><code>    XmlSchemaSet schemaSet = new XmlSchemaSet();
      foreach (string sd in Schemas)
      {
          using (XmlReader r = XmlReader.Create(new FileStream(sd, FileMode.Open)))
          {
              schemaSet.Add(XmlSchema.Read(r, null));
          }
      }
      schemaSet.CompilationSettings = new XmlSchemaCompilationSettings();
      schemaSet.Compile();
  </code></pre>
  
  <p>The .Compile() fails because "Type 'a:TheSimpleType' is not declared, or is not a simple type."</p>
  
  <p>However, it works if either:</p>
  
  <ul>
  <li>the namespace is removed from the schema, or</li>
  <li>the namespace is added to the include.</li>
  </ul>
  
  <p>The question is: how do I get C# to accept it without editing the schemata?</p>
  
  <p>I suspect the problem is that although I have put both schemata into the XmlSchemaSet, I still need to tell C# that one is included into the other, i.e., it hasn't worked it out for itself. Indeed, if I only tell the XmlSchemaSet about the main XSD (and not the include) (both without (or with) namespaces) then "Type 'TheSimpleType' is not declared, or is not a simple type."</p>
  
  <p>Thus this seems to be a question about resolving includes: how?!</p>