For validation to be possible, the XML document needs to be associated to a DTD or an XML schema. Up until this point, this lesson has concentrated on the non-validating parser.This section examines the validating parser to find out what happens when you use it to parse the sample program.To be notified of validation errors in an XML document, the parser factory must be configured to create a validating parser, as shown in the preceding section.In addition, the following must be true: Note - The parser factory must be configured to generate a parser that is namespace-aware as well as validating. More information about namespaces is provided in Document Object Model but for now, understand that schema validation is a namespace-oriented process.
From the standpoint of an application that is interested in processing only the XML data, that is a good thing because the application is never bothered with white space that exists purely to make the XML file readable.Note - More information about namespaces is included in Validating with XML Schema in Document Object Model.For now, think of these attributes as the "magic incantation" you use to validate a simple XML file that does not use them.On the other hand, if you are writing an application that filters an XML data file and if you want to output an equally readable version of the file, then that white space would no longer be irrelevant: it would be essential.To get those characters, you would add the This code simply generates a message to let you know that ignorable white space was seen. The SAX specification does not require that this method be invoked.