Disable DTD validation
<p>I am using below code to parse an xml and validate with a xsd file. Xml file also contains reference to a .dtd which is irrelevant here.<br>
How can I disable DTD processing?   </p>

<pre class="lang-java prettyprint-override"><code>DocumentBuilderFactory factory =  DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);     
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",  "http://www.w3.org/2001/XMLSchema" );
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", XmlSchemaUrl);

DocumentBuilder builder =factory.newDocumentBuilder();

Validator handler=new Validator();
builder.setErrorHandler(handler);

InputSource is =  new InputSource(new StringReader(xmlDoc));
Document doc = builder.parse(is);
if(handler.validationError==true)
{
    throw handler.saxParseException;
}
else
    return true;
</code></pre>

<p>Below is the XML I am trying to parse</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;  
&lt;!DOCTYPE document SYSTEM "subjects.dtd"&gt;             
&lt;Request&gt;
    &lt;Header&gt;   
        &lt;UserName&gt;test&lt;/UserName&gt;
        &lt;ApplicationName&gt;MyAccount&lt;/ApplicationName&gt;
    &lt;/Header&gt;
    &lt;GetCustomerDetails&gt;
        &lt;AccountInternalId&gt;12345678&lt;/AccountInternalId&gt;
    &lt;/GetCustomerDetails&gt;
&lt;/Request&gt;
</code></pre>