title: XML Validation in Java: processContents="lax" seems not to work correctly
body: <p>I have an XML Schema which contains a number of</p>
  
  <pre><code>&lt;any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /&gt;
  </code></pre>
  
  <p>definitions, i.e., it allows to insert arbitrary tags of other namespaces. <code>processContents="lax"</code> indicates that the parser should try do validate these tags, if it has the according schema <a href="http://www.w3.org/TR/xmlschema-0/#ref33" rel="noreferrer">(1)</a> <a href="http://www.w3schools.com/schema/el_any.asp" rel="noreferrer">(2)</a>.</p>
  
  <p>For me this means, that if I give the parser all schema documents, and there is an invalid XML tag of one of the secondary namespaces, it needs to report an error.</p>
  
  <p>However, it seems that the Java XML validator ignores such errors. I have verified that the parser has all the necessary schema documents to perform the validation (if I change the XML schema to <code>processContents="strict"</code>, it works as expected and uses the secondary schema documents for validation). It seems that for the validator behaves as if the attribute is specified with value <code>skip</code>.</p>
  
  <p><strong><em>Java code for validation:</em></strong></p>
  
  <pre><code>/*
   * xmlDokument is the file name of the XML document
   * xsdSchema is an array with all schema documents
   */
  public static void validate( String xmlDokument, Source[] xsdSchema ) throws SAXException, IOException {   
    SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
    Schema schema = schemaFactory.newSchema( xsdSchema );
    Validator validator = schema.newValidator();
    validator.setErrorHandler( new MyErrorHandler() );
    validator.validate( new StreamSource(new File(xmlDokument)) );
  }
  </code></pre>
  
  <p><strong><em>Minimal example:</em></strong></p>
  
  <p>The primary schema:</p>
  
  <pre><code>&lt;xs:schema
      xmlns="baseNamespace"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="baseNamespace"
      xmlns:tns="baseNamespace"&gt;
  
  &lt;!-- Define single tag "baseTag" --&gt;
  &lt;xs:element name="baseTag"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>The secondary schema:</p>
  
  <pre><code>&lt;xs:schema
      xmlns="secondaryNamespace"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="secondaryNamespace"
      xmlns:tns="secondaryNamespace"
      elementFormDefault="qualified"
      attributeFormDefault="qualified"&gt;
  
  &lt;xs:element name="additionalTag"/&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>The XML document I am trying to validate:</p>
  
  <pre><code>&lt;baseTag
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="baseNamespace"
    xmlns:secondary="secondaryNamespace"
    xsi:schemaLocation="
      baseNamespace base.xsd
      secondaryNamespace secondary.xsd"&gt;
  
    &lt;secondary:additionalTag/&gt;
    &lt;secondary:invalidTag/&gt;
  &lt;/baseTag&gt;
  </code></pre>
  
  <p>Using the above Java code giving both schema documents does not produce any validation errors, only if I change the <code>lax</code> to <code>strict</code> in the base schema (which I don't want). The error message in this case is</p>
  
  <pre><code>cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'secondary:invalidTag'.
  </code></pre>
  
  <p><strong><em>Questions:</em></strong></p>
  
  <p>Did I misunderstand something and is this actually the correct behavior? Or am I right regarding <code>processContents</code>?</p>
  
  <p>Are my schema documents doing the right thing?</p>
  
  <p>Is my Java code correct? How could I change it so that it behaves as expected?</p>