An XML document is considered ‘well-formed’ if it follows the normal rules of XML. In the example below we look at validating an XML document while using DOM, SAX and St AX.
(For SAX parsing, on the other hand, you set a property on the parser generated by the factory).A JAXP implementation could legally use a DOM parser in this case, but there is no reason to. In debian squeeze it is located in the package "libxerces-c-samples".If you use a DOM parser explicitly for validation, you will definitely instantiate a DOM tree.// parse an XML document into a DOM tree Document Builder parser = Document Builder Instance()Document Builder(); Document document = parser.parse(new File("instance.xml")); // create a Schema Factory capable of understanding WXS schemas Schema Factory factory = Schema Instance(XMLConstants. If I use an Error Handler (own class that implements Error Handler) instead, it recognizes all errors, but the try-catch-block of validator.validate does not throw any Exception.. The definition of the dtd and xsd has to be in the xml! If you are generating XML files programatically, you may want to look at the XMLBeans library.Now that the program is ready to validate with an XML Schema definition, it is necessary only to ensure that the XML document is associated with (at least) one.There are two ways to do that: , which stands for "XML Schema instance." The second line specifies the schema to use for elements in the document that do not have a namespace prefix-that is, for the elements you typically define in any simple, uncomplicated XML document.