Try OpenEdge Now
skip to main content
Working with XML
Reading XML Documents with the Simple API for XML (SAX) : Understanding ABL SAX : Validation
 

Validation

The SAX-reader object always checks that the XML document is well formed. In addition, the SAX-reader object can validate the XML document against a DTD or XML Schema or both.
Validation of an XML document read into a SAX-reader object can be accomplished by providing a DTD, one or more XML Schemas, or both. The following table provides a summary of how to perform the validation tasks required to support your desired validation scheme.
Table 10. Validation schemes
Validation task
Required action
Disable DTD validation
Set the VALIDATION-ENABLED attribute of the SAX-reader object to FALSE. All DTDs will be ignored.
Enable DTD validation
Set the VALIDATION-ENABLED attribute of the SAX-reader object to TRUE. If the parser does not find a DTD, the parse fails. Validation errors are caught in a callback event procedure named error. If this callback procedure is not implemented, then validation errors cannot be caught.If the DTD is not included within the parsed XML document, provide the DTD location by setting the SCHEMA-PATH attribute of the SAX-reader object. If this attribute is set, DTDs found or referenced from within the XML document are ignored in favor of the specified DTD.
Disable XML Schema validation
Set the SCHEMA-LOCATION and NONAMESPACE-SCHEMA-LOCATION attributes to the empty string ("").
Note: XML documents may refer to the schemas to which they must conform using an xsi:schemaLocation attribute and/or an xsd:noNamespaceSchemaLocation attribute. If the XML document does include these references, setting these SAX-reader attributes to the empty string ("") does not disable validation against the referenced schemas.
Enable XML Schema validation
Specify the location of one or more XML Schema documents with the SCHEMA-LOCATION attributes and/or the NONAMESPACE-SCHEMA-LOCATION attribute of the SAX-reader object.
Enable both DTD and XML Schema validation
Set the VALIDATION-ENABLED attribute to TRUE and provide valid SCHEMA-PATH. Specify the location of one or more XML Schema documents with the SCHEMA-LOCATION attribute and/or the NONAMESPACE-SCHEMA-LOCATION attributes of the SAX-reader object.
A DTD might be completely included in the XML document. Alternatively, part or all of the DTD might reside in one or more external files named in the XML document. In the latter case, to override the locations given in the XML document, use one or both of the following techniques:
*Implement the ResolveEntity callback procedure
*Set the SAX-reader object's SCHEMA-PATH attribute
Note: Even when VALIDATION-ENABLED is FALSE, the parser still reads any specified DTD (internal or external) to get information on entities.
For more information, see the reference entries for the VALIDATION-ENABLED and SCHEMA-PATH attributes in OpenEdge Development: ABL Reference.
Similarly, to use XML Schema for validation, set the following attributes or use the method to declare your namespace and location pairs for the XML Schema documents:
*SCHEMA-LOCATION attribute
*ADD-SCHEMA-LOCATION( ) method
*NONAMESPACE-SCHEMA-LOCATION attribute
For more information, see these reference entries in OpenEdge Development: ABL Reference.
Note: The parser will validate against both a DTD and XML Schema if both types of validation are properly specified.