Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 1 Introduction : Example of Converting a Copybook Schema to an XSD

Example of Converting a Copybook Schema to an XSD
The Copybook Schema resource converts a COBOL Copybook into an XSD that is used to parse COBOL data into an XML document and conversely render XML as COBOL data. The following COBOL Copybook is a simple example of a data schema for a purchase order.
 
01 PURCHASE-ORDER.
   02 HEADER.
      03 DOCUMENT-DEP PIC 9.
      03 DOCUMENT-DATE-TIME PIC X(20) VALUE IS SPACES.
   02 LINEITEM.
      03 ORDERITEM-DEP PIC 9.
      03 QUANTITY PIC 9(4) USAGE IS COMP-3.
      03 UNIT-PRICE.
         04 UNIT-PRICE-CONTROL PIC X.
         04 ACTUAL.
            05 CURRENCY PIC X(10) VALUE IS SPACES.
            05 FILLER PIC 99.
The example Copybook schema above is converted to the following XSD:
 
<xs:schema xmlns:cobol=http://xmlns.tibco.com/cobol2schema
xmlns:xs=http://www.w3.org/2001/XMLSchema
obol:copybookType="COBOL" obol:prefix=""
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
  <xs:complexType name="_ROOT_TYPE">
    <xs:choice>
      <xs:element cobol:byteLength="38" cobol:byteOffset="0"
      name="PURCHASE-ORDER" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element cobol:byteLength="21" cobol:byteOffset="0"
            name="HEADER" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element cobol:byteLength="1"
                  cobol:picture="9"
                  cobol:fullName="PURCHASE-ORDER.HEADER.DOCUMENT-
                    DEP"
                  cobol:byteOffset="0" cobol:usage="DISPLAY"
                  name="DOCUMENT-DEP" minOccurs="0">
                    <xs:simpleType>
                      <xs:restriction base="xs:unsignedShort">
                        <xs:totalDigits value="1"/>
                        <xs:minInclusive value="0"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                  <xs:element cobol:byteLength="20"
                  cobol:picture="X(20)"
                  cobol:fullName="PURCHASE-ORDER.HEADER.DOCUMENT-
                    DATE-TIME"
                  cobol:byteOffset="1" cobol:usage="DISPLAY"
                  name="DOCUMENT-DATE-TIME" default="SPACES"
                  minOccurs="0">
                    <xs:simpleType>
                      <xs:restriction base="xs:string">
                        <xs:maxLength value="20"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element cobol:byteLength="17"
            cobol:byteOffset="21" name="LINEITEM" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element cobol:byteLength="1"
                  cobol:picture="9"
                  cobol:fullName="PURCHASE-ORDER.LINEITEM.
                    ORDERITEM-DEP"
                  cobol:byteOffset="21" cobol:usage="DISPLAY"
                  name="ORDERITEM-DEP" minOccurs="0">
                    <xs:simpleType>
                      <xs:restriction base="xs:unsignedShort">
                        <xs:totalDigits value="1"/>
                        <xs:minInclusive value="0"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                  <xs:element cobol:byteLength="3"
                  cobol:picture="9(4)"
                  cobol:fullName="PURCHASE-ORDER.LINEITEM.
                    QUANTITY"
                  cobol:byteOffset="22"
                  cobol:usage="PACKED-DECIMAL" name="QUANTITY"
                  minOccurs="0">
                    <xs:simpleType>
                      <xs:restriction base="xs:unsignedShort">
                        <xs:totalDigits value="4"/>
                        <xs:minInclusive value="0"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                  <xs:element cobol:byteLength="13"
                  cobol:byteOffset="25" name="UNIT-PRICE"
                  minOccurs="0">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element cobol:byteLength="1"
                        cobol:picture="X"
                        cobol:fullName="PURCHASE-ORDER.LINEITEM.
                          UNIT-PRICE.UNIT-PRICE-CONTROL"
                        cobol:byteOffset="25"
                        cobol:usage="DISPLAY"
                        name="UNIT-PRICE-CONTROL" minOccurs="0">
                          <xs:simpleType>
                            <xs:restriction base="xs:string">
                              <xs:maxLength value="1"/>
                            </xs:restriction>
                          </xs:simpleType>
                        </xs:element>
                        <xs:element cobol:byteLength="12"
                        cobol:byteOffset="26"
                        name="ACTUAL" minOccurs="0">
                          <xs:complexType>
                            <xs:sequence>
                              <xs:element cobol:byteLength="10"
                              cobol:picture="X(10)"                               cobol:fullName="PURCHASE-ORDER.LINE
                                ITEM.UNIT-PRICE.ACTUAL.CURRENCY"
                              cobol:byteOffset="26"
                              cobol:usage="DISPLAY"
                              name="CURRENCY"
                              default="SPACES" minOccurs="0">
                                <xs:simpleType>
                                  <xs:restriction base=
                                  "xs:string">
                                    <xs:maxLength value="10"/>
                                  </xs:restriction>
                                </xs:simpleType>
                              </xs:element>
                              <xs:element cobol:byteLength="2"
                              cobol:picture="99"                               cobol:fullName="PURCHASE-ORDER.LINE
                                ITEM.UNIT-PRICE.ACTUAL.FILLER"
                              cobol:byteOffset="36"
                              cobol:usage="DISPLAY"
                              name="FILLER" minOccurs="0">
                                <xs:simpleType>
                                  <xs:restriction base=
                                  "xs:unsignedShort">
                                    <xs:totalDigits value="2"/>
                                    <xs:minInclusive value="0"/>
                                  </xs:restriction>
                                </xs:simpleType>
                              </xs:element>
                            </xs:sequence>
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>
</xs:schema
 

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved