Each approach described in 4.4.1 How to Set the XML Schema Properties for the DOM Parser and 4.4.2 How to Set the XML Schema Properties SAX Parser sets the schema document by using the property. Alternatively, you can identify the schema document directly in the XML document to be validated. Note that if you identify the schema document both in the XML document and by using the property, the schema document identified by using the property is used.
To identify the schema document in the XML document to be validated, use the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute. Which attribute to use depends on whether the namespace is defined in the schema document. The following table lists the types of schema document to identify and the attributes to use for them.
Table 4-4 Types of the schema document to identify and the attributes to use for them
Type of schema document to identify | Attribute to use |
---|---|
Schema document with the namespace defined | xsi:schemaLocation |
Schema document with no namespace defined | xsi:noNamespaceSchemaLocation |
When using the xsi:schemaLocation attribute, specify both the namespace URI of the elements and attributes declared in the schema document to identify and the name of the schema document to identify, separated by a space.
Both the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes belong to the namespace http://www.w3.org/2001/XMLSchema-instance. Therefore, when these attributes are used to identify a schema document, the namespace http://www.w3.org/2001/XMLSchema-instance needs to be declared.
The follow shows an example of specifying a schema document by using the xsi:schemaLocation: