4.4.2 How to Set the XML Schema Properties SAX Parser
To set any XML Schema properties to the SAX parser, use the setProperty method of the javax.xml.parsers.SAXParser class. How to set a property is shown below.
The following describes the coding example. Each item number corresponds to the number in the comments in the coding example.
-
Perform the setting that enables validation.
Set the argument of the setValidating method on the javax.xml.parsers.SAXParserFactory class to true. This setting enables the XML document validation function.
-
Set to comply with the XML Schema specification.
Using the setProperty method of the javax.xml.parsers.SAXParser class, for the property string "http://java.sun.com/xml/jaxp/properties/schemaLanguage" set the value "http://www.w3.org/2001/XMLSchema", which indicates that validation will follow the XML Schema specification.
-
Identify the schema document.
Using the setProperty method of the javax.xml.parsers.SAXParser class, for the property string "http://java.sun.com/xml/jaxp/properties/schemaSource" specify the schema document used for validation. This specification is not necessary if the schema document is identified in the XML document.