The set Error Handler() method invokes an object of Doucment Builder.Enable the set Validating() method of the factory to "true".The Error Handler used for the examples is a very simple one which reports the error to and continues until the XML document has been fully parsed or until a fatal-error has been reported.Namespaces have been introduced to XML after the first specification of XML had received the official W3C Recommendation status.Configure Java APIs (SAX, DOM, dom4j, XOM) using JAXP 1.3 to validate XML Documents with DTD and Schema(s).Many Java XML APIs provide mechanisms to validate XML documents, the JAXP API can be used for most of these XML APIs but subtle configuration differences exists.
The output of the program demonstrating both validation success and failure scenarios is shown below.This article demonstrates how to validate an XML document against a DTD by using Woodstox. It defines the employee element that contains id, name and salary sub-elements. Then try to validate invalid (see line 46 below)and verify that the validation fails . From the main method, first successfully validate the valid file (see line 45 below).Description of program: Validating a XML file against a DTD needs a xml file and its DTD document.First of all construct a well-formed xml file along with a DTD file .