Validating xml sax
In this section we shall validate the example XML document with XML schema document catalog.xsd, with the SAXParser class. Create a SAXParser object and set the validation mode of the SAXParser object to SCHEMA_VALIDATION, as shown in the following listing: Validates the complete XML document with an XML schema if the parser is able to find a schema.If the parser is not able find a schema or if the XML document does not conform to the schema, an error is raised.uses the non-validating parser by default, but it can also activate validation.Activating validation allows the application to tell whether the XML document contains the right tags or whether those tags are in the right sequence.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.This article shows five ways of how to configure different Java APIs (including DOM, SAX, dom4j and XOM) using JAXP 1.3 for checking and validating XML with DTD and Schema(s).
This is the reason why (most of the) XML parser implementations do not support XML Namespaces by default, to handle the validation of XML documents with namespaces correctly it is therefore necessary to configure the underlying parsers to provide support for XML Namespaces.In other words, it can tell you whether the document is valid.If validation is not activated, however, it can only tell whether or not the document is well-formed, as was shown in the previous section when you deleted the closing tag from an XML element. however, the import statement does not adequately inform the schema processor where to locate the actual schema.
hence, you must provide it explicitly, or provide a way to load it on the fly.SAXParser is recommended if SAX parsing event notification is required in addition to validation with a schema.