Generating XML-enhanced COBOL from an XML Schema

The schema produced by cbl2xml using the format described in Generating a Copybook and Schema conforms to your existing COBOL record, and contains element names derived from your COBOL record. In practical application, a schema of this sort is limited because to exchange XML information with another party, you must use element names recognized by the other party. For example, many industries publish industry-standard schemas, which contain a specific set of elements used to exchange information throughout the industry. To generate COBOL records that contain XML syntax extensions that conform to a third-party schema, use the following cbl2xml format:

cbl2xml XMLschema 
                 [-c cobolFile]
                 [-d directiveFile]
                 [-prompt | -noprompt]

In this example, we use a fictional industry-standard schema named widgets.xsd. This schema enables companies to exchange ordering information for the Widget product. The contents of widgets.xsd is as follows:

Industry-standard XML schema for "widgets"

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 elementFormDefault="qualified">
	<xsd:element name="Availability" type="xsd:string"/>
	<xsd:element name="Base_Price" type="xsd:string"/>
	<xsd:element name="Base_Price_And_Unit">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="Base_Price"/>
				<xsd:element ref="Unit"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Catalogue_Id" type="xsd:int"/>
	<xsd:element name="widgets">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="Product_Id" minOccurs="0"/>
				<xsd:element ref="Company_Id"/>
				<xsd:element ref="Catalogue_Id"/>
				<xsd:element ref="SKU"/>
				<xsd:element ref="Product_Series" minOccurs="0"/>
				<xsd:element ref="Availability"/>
				<xsd:element ref="Sale"/>
				<xsd:element ref="Base_Price_And_Unit"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Company_Id" type="xsd:int"/>
	<xsd:element name="Product_Id" type="xsd:int"/>
	<xsd:element name="Product_Series" type="xsd:string"/>
	<xsd:element name="SKU" type="xsd:string"/>
	<xsd:element name="Sale" type="xsd:string"/>
	<xsd:element name="Unit" type="xsd:string"/>
</xsd:schema>

CBL2XML reads this schema and generates a copybook, widgets.cpy, as follows:

XML-enabled COBOL generated from widgets.cpy

       01 Widgets identified by "Widgets".
        02 Product-Id PIC X(80) identified by "Product_Id" 
           count in Product-Id-count.
        02 Company-Id PIC X(80) identified by "Company_Id" 
           count in Company-Id-count.
        02 Catalogue-Id PIC X(80) identified by "Catalogue_Id" 
           count in Catalogue-Id-count.
        02 SKU PIC X(80) identified by "SKU" count in SKU-count.
        02 Product-Series PIC X(80) 
            identified by "Product_Series" 
            count in Product-Series-count.
        02 Availability PIC X(80) identified by "Availability" 
           count in Availability-count.
        02 Sale PIC X(80) identified by "Sale" 
           count in Sale-count.
        02 Base-Price-And-Unit 
           identified by "Base_Price_And_Unit" 
           count in Base-Price-And-Unit-count.
         03 Base-Price PIC X(80) 
            identified by "Base_Price" 
            count in Base-Price-count.
         03 Unit PIC X(80) 
            identified by "Unit" 
            count in Unit-count.

You can then include this copybook in a COBOL program you want to use to send and receive information about widgets.