0

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.
How can I disable DTD processing?

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;

Below is the XML I am trying to parse

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>  
<!DOCTYPE document SYSTEM "subjects.dtd">             
<Request>
    <Header>   
        <UserName>test</UserName>
        <ApplicationName>MyAccount</ApplicationName>
    </Header>
    <GetCustomerDetails>
        <AccountInternalId>12345678</AccountInternalId>
    </GetCustomerDetails>
</Request>
Community
  • 1
  • 1
user3366906
  • 149
  • 2
  • 11

0 Answers0