title: Potential bug in lxml(etree.XMLSchema) : doesn't verify IDREF relationships in xml document
body: <p>I am using the lxml XMLSchema object to validate an xml file against my xsd which specifies xs:ID and xs:IDREF constraints. However, lxml apparently validates xml document to true even if there is no corresponding ID for the IDREF.</p>
  
  <p>Any ideas on how to resolve this issue?</p>
  
  <p>Edit:</p>
  
  <p>XSD:
      </p>
  
  <pre><code>&lt;xs:schema
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.chaos.com"
  xmlns="http://www.chaos.com"
  elementFormDefault="qualified"&gt;
  
  &lt;xs:complexType name="ModuleType"&gt;
      &lt;xs:attribute name="id" type="xs:ID" use="required"/&gt;
      &lt;xs:attribute name="path" type="xs:string" use="required"/&gt;
      &lt;xs:anyAttribute processContents="lax"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="ModulesType" mixed="true"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="Module" type="ModuleType" minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:anyAttribute processContents="lax"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FrameworkType" mixed="true"&gt;
      &lt;xs:all&gt;
          &lt;xs:element name="Good"&gt;
              &lt;xs:complexType&gt;
                  &lt;xs:attribute name="moduleId" type="xs:IDREF" use="required"/&gt;
                  &lt;xs:anyAttribute processContents="lax"/&gt;
              &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
          &lt;xs:element name="Bad"&gt;
              &lt;xs:complexType&gt;
                  &lt;xs:attribute name="moduleId" type="xs:IDREF" use="required"/&gt;
                  &lt;xs:anyAttribute processContents="lax"/&gt;
              &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
      &lt;/xs:all&gt;
      &lt;xs:anyAttribute processContents="lax"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="TestbenchType" mixed="true"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="Modules" type="ModulesType"/&gt;
          &lt;xs:element name="Framework" type="FrameworkType"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:element name="Testbench" type="TestbenchType"/&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>XML:
      </p>
  
  <pre><code>&lt;Testbench xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.chaos.com"&gt;
  
  &lt;Modules&gt;
      &lt;Module id="Module1" path="Testbench_module1.py"/&gt;
      &lt;Module id="Module2" path="Testbench_module2.py"/&gt;
  &lt;/Modules&gt;
  
  &lt;Framework&gt;
      &lt;Good moduleId="Module1"/&gt;
      &lt;Bad moduleId="ModuleX"/&gt;
  &lt;/Framework&gt;
  
  &lt;/Testbench&gt;
  </code></pre>
  
  <p>Python Validation code:</p>
  
  <pre><code>from lxml import etree
  from cStringIO import StringIO
  
  try:
      #Get schema
      buf_schema = StringIO()
      with open(schema,'r') as fh:
          for line in fh: buf_schema.write(line)
      buf_schema.seek(0)
      Schema = etree.XMLSchema(etree.parse(buf_schema))
      buf_schema.close()
  
      # Validate
      buf_cfg = StringIO()
      with open(cfg,'r') as fh:
          for line in fh: buf_cfg.write(line)
      buf_cfg.seek(0)
      Schema.assertValid(etree.parse(buf_cfg))
      buf_cfg.close()
  except etree.XMLSyntaxError, err:
      return False, str(err)
  except Exception, err:
      return False, str(err)
  return True,None
  </code></pre>
  
  <p>This function returns True for the given XSD/XML even though the attribute moduleId of the element Bad is in violation of its IDREF constraint</p>