title: Xerces enforces Element declarations if DTD DOCTYPE is present
body: <p>I have the follwoing XML document:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;!DOCTYPE root [&lt;!ENTITY foo &quot;bar&quot;&gt;]&gt;
  &lt;root&gt;
      &lt;child&gt;&amp;foo;&lt;/child&gt;
  &lt;/root&gt;
  </code></pre>
  <p>and I want to validate it against the following XSD schema:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; elementFormDefault=&quot;qualified&quot;&gt;
      &lt;xs:element name=&quot;root&quot;&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name=&quot;child&quot; type=&quot;xs:string&quot;/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  <p>For this I'm using a small ANT script:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;project basedir=&quot;.&quot; name=&quot;schema-validation-test&quot; default=&quot;test&quot;&gt;
    &lt;target name=&quot;test&quot;&gt;
        &lt;schemavalidate failonerror=&quot;true&quot; file=&quot;src.xml&quot; nonamespacefile=&quot;schema.xsd&quot;&gt;
            
        &lt;/schemavalidate&gt;
    &lt;/target&gt;
  &lt;/project&gt;
  </code></pre>
  <p>Though the XML structure is valid against the XSD I get the errors:</p>
  <pre><code>[schemavalidate] ...\src.xml:2:7: Elementtyp &quot;root&quot; muss deklariert werden.
  [schemavalidate] ...\src.xml:3:12: Elementtyp &quot;child&quot; muss deklariert werden.
  </code></pre>
  <p>(Original messages, translated it means: <code>'Element type &quot;root&quot; must be declared'</code>)</p>
  <p>I think I know what happens: Xerces finds the DTD declaration and tries to validate the XML against it. I need to turn off the DTD validation (without turning off the full validation) or to specify that elements or attributes that do not have a declaration do not produce an error. I played around a lot with the Xerces features (<a href="https://xerces.apache.org/xerces-j/features.html" rel="nofollow noreferrer">https://xerces.apache.org/xerces-j/features.html</a>), but didn't find a satisfying setup.</p>
  <p>Thanks for any help or hint!</p>
  <p><strong>Version information:</strong></p>
  <ul>
  <li>Java: 1.8.0_211</li>
  <li>Ant: 1.9.13</li>
  <li>Xerces: <em>not sure, how to find out?</em></li>
  </ul>
  <p><strong>UPDATE:</strong> found my Xerces version: Xerces-J 2.7.1 (for ant, execute: <code>&lt;java classname=&quot;com.sun.org.apache.xerces.internal.impl.Version&quot;/&gt;</code>)</p>
  <p><em>Note:</em> I'm using Ant here, but if you have a solution in Java, it may also be helpful.</p>