java ignore the DTD for validation if a schema is available

Arremyherse

New Member
Is this possible to ignore an internal DTD for validation, when a document has XSD schema available? DTD should be used for validation if no schema specified in the source document.Here's how I configure the parser.\[code\]DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();factory.setValidating(false);factory.setNamespaceAware(true);factory.setFeature("http://apache.org/xml/features/validation/dynamic", true);factory.setSchema(schemaFactory.newSchema());builder.setErrorHandler(errorHandler);\[/code\]I use the "dynamic" feature to make the parser perform DTD validation only if the DTD is specified.I cannot get rid of DTD validation at all, I need to ignore it only if the source XML document has XSD schema.Sometimes the DTD declaration is used only to declare DTD entities and the schema reference is used for validation against a W3C XML Schema. The problem is DTD validation can be performed only at the time of parsing and before that I don't know whether a document has internal references to DTD or XSD.
 
Back
Top