182 Extremely pureXML in DB2 10 for z/OS
8.3.3 Validation of XML documents in COBOL
Finally, COBOL also offers validation of XML documents against an XML schema through a
variant of the XML PARSE statement. This approach requires Enterprise COBOL for z/OS
The schema does not have to be registered anywhere, but it does have to be in a
preprocessed format known as
Optimized Schema Representation (OSR). This preprocessing
can be done from UNIX System Services with a command such as in Example 8-26. First, the
schema is copied to UNIX System Services from TSO, and then the OSR document is
Example 8-26 Converting a schema to OSR format
cp -B "//'XMLR2.BKSTMT.XSD'" /u/xmlr2/bkstmt.xsd
xsdosrg -v -o /u/xmlr2/bkstmt.osr /u/xmlr2/bkstmt.xsd
We extend the XML PARSE statement in Example 8-25 on page 181 with the validating
phrase shown in Example 8-27.
Example 8-27 XMLPARSE with schema validation
XML-SCHEMA RSCHEMA IS 'DDSCHEMA'.
XML PARSE RCPT
WITH ENCODING 1208
VALIDATING WITH FILE RSCHEMA
PROCESSING PROCEDURE GET-DATA
We use the schema declaration in the SPECIAL-NAMES section to associate the schema
name RSCHEMA with an external file that contains the schema. This association can then be
supplied as a DD statement in the JCL to run the COBOL program, as shown
Example 8-28 DD statement for supplying a schema to the COBOL program
//GO.DDSCHEMA DD PATH='/u/xmlr2/bkstmt.osr'
As mentioned previously, the automatic schema validation that can be set up in DB2, simply
by associating an XML type identifier with the XML column, is robust to schema changes and
can be easy to work with. This choice is generally better than explicit schema validation in
both DB2 and COBOL.