I am using javax.xml.validation.Validator to validate my xml as below -
Validator validator = myschema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlString)));
I would like to prevent XML External Entity attacks by disabling DTDs (Document Type Definitions) completely, so I'd like for the validator to throw an exception in case of a DTD in my xml if possible. I have read about doing this using DocumentBuilderFactory
. How do i do configure this in Validator?