Sun's implementation supports any combination of configuration options.
(If a combination is not supported by a particular implementation, it is required to generate a factory configuration error.) 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 existing schema written in the XML Schema language.
(Even a DTD qualifies as a "schema", although it is the only one that does not use XML syntax to describe schema constraints.) However, "XML Schema" presents us with a terminology challenge.
Parser doesn t support setschema not validating
(You can also examine the sample programs that are part of the JAXP download.
They use a simple XML Schema definition to validate personnel data stored in an XML file.)Note: There are multiple schema-definition languages, including RELAX NG, Schematron, and the W3C "XML Schema" standard.
In addition, the following must be true: You'll learn more about namespaces in Validating with XML Schema.
For now, understand that schema validation is a namespace-oriented process.
Since JAXP-compliant parsers are not namespace-aware by default, it is necessary to set the property for schema validation to work.
You also set a factory attribute specify the parser language to use.
Here, you use the constants you defined earlier to specify the W3C's XML Schema language: In the process, however, there is an extra error to handle. In addition to the error handling you've already learned about, there is one error that can occur when you are configuring the parser for schema-based validation.
If the parser is not 1.2-compliant and therefore does not support XML Schema, it can throw a Note: You'll learn about namespaces in Validating with XML Schema.
(For SAX parsing, on the other hand, you set a property on the parser generated by the factory.)The first attribute defines the XML Name Space (xmlns) prefix, "xsi", where "xsi" 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.
Because JAXP-compliant parsers are not namespace-aware by default, it is necessary to set the property for schema validation to work.