title: java xml validation JDK 1.5 JDK 1.6 difference
body: <p>I have a problem with Java xml validation. </p>
  
  <p>I have the following xsd:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xsd:element name="TEST"&gt;
      &lt;xsd:complexType&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="LAST_NAME"&gt;
            &lt;xsd:simpleType&gt;
              &lt;xsd:restriction base="xsd:string"&gt;
                &lt;xsd:minLength value="1" /&gt;
                &lt;xsd:maxLength value="30" /&gt;
              &lt;/xsd:restriction&gt;
            &lt;/xsd:simpleType&gt;
          &lt;/xsd:element&gt;
          &lt;xsd:element name="FIRST_NAME"&gt;
            &lt;xsd:simpleType&gt;
              &lt;xsd:restriction base="xsd:string"&gt;
                &lt;xsd:minLength value="1" /&gt;
                &lt;xsd:maxLength value="20" /&gt;
              &lt;/xsd:restriction&gt;
            &lt;/xsd:simpleType&gt;
          &lt;/xsd:element&gt;
          &lt;xsd:element name="DOB" nillable="true" type="xsd:date" /&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:complexType&gt;
    &lt;/xsd:element&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>and xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;LAST_NAME&gt;Lastname&lt;/LAST_NAME&gt;
    &lt;FIRST_NAME&gt;Firstname&lt;/FIRST_NAME&gt;
    &lt;DOB xsi:nil="true"/&gt;
  &lt;/TEST&gt;
  </code></pre>
  
  <p>The (simplified) code of my validator:</p>
  
  <pre><code>boolean valid=true;
  try {
      Source schemaSource = new StreamSource(xsdInputStream);
      DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document document = parser.parse(xmlInputStream);
      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  
      Schema schema = factory.newSchema(schemaSource);
  
      Validator validator = schema.newValidator();
      try {
          validator.validate(new DOMSource(document));
      } catch (SAXException e) {
          logger.log(Level.INFO, e.getMessage(), e);
          valid = false;
      }
  
  } catch( Exception ex ) {
      logger.log(Level.SEVERE, ex.getMessage(), ex);
      valid=false;
  }
  </code></pre>
  
  <p>The testprogram has a different behavior in JDK 1.5 and JDK 1.6. The xml is valid in JDK 1.5 but invalid in JDK 1.6. The error message is the following:</p>
  
  <pre><code>Element 'DOB' is a simple type, so it cannot have attributes, excepting those whose namespace name is identical to 'http://www.w3.org/2001/XMLSchema-instance' and whose [local name] is one of 'type', 'nil', 'schemaLocation' or 'noNamespaceSchemaLocation'. However, the attribute, 'xsi:nil' was found.
  </code></pre>
  
  <p>Which JDK is correct? How to change the xml/xsd to be valid in both?</p>