Validating the xml
Although a full treatment of XML Schema is beyond the scope of this tutorial, this section shows you the steps you take to validate an XML document using an XML Schema definition.
(To learn more about XML Schema, you can review the online tutorial, XML Schema Part 0: Primer.
At the end of this section, you will also learn how to use an XML Schema definition to validate a document that contains elements from multiple namespaces.
To be notified of validation errors in an XML document, the following must be true: It is helpful to start by defining the constants you will use when configuring the factory.
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.
(You will see how to deal with multiple namespaces in the next section.) You can also specify the schema file in the application, which is the case for Here, too, there are mechanisms at your disposal that will let you specify multiple schemas. Namespaces let you combine elements that serve different purposes in the same document without having to worry about overlapping names.
You also set a factory attribute to specify the parser language to use.
(For SAX parsing, on the other hand, you set a property on the parser generated by the factory).
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.
Note - The material discussed in this section also applies to validating when using the SAX parser.
You are seeing it here, because at this point you have learned enough about namespaces for the discussion to make sense.