To set any XML Schema properties to the DOM parser, use the setAttribute method of the javax.xml.parsers.DocumentBuilderFactory class. How to set a property is shown below.
![[Figure]](figure/zu040d00.gif)
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.DocumentBuilderFactory class to true. This setting enables the XML document validation function.
- Set the schema language to use for schema validation.
Using the setAttribute method of the javax.xml.parsers.DocumentBuilderFactory 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 setAttribute method of the javax.xml.parsers.DocumentBuilderFactory 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.