THE DAILY DIGEST

The daily edition.

Essential reading from Rocket Enterprise. Straight to the source.

Archived edition
DAILY EDITION1 story· 5 min read
IN FOCUS

CBL2XML: Bi-Directional Schema Mapping, XML Syntax Extensions, and the PREXML Preprocessor

In Rocket Enterprise Developer 12.0 for Linux/UNIX, the cbl2xml command-line utility transforms COBOL copybooks into XML-enhanced structures with IDENTIFIED BY clauses and generates matching XML schemas (XSD). Using a two-stage mapping workflow with XML map files (.map), developers bind COBOL field names to third-party XML elements, attributes, and namespaces. Programs process generated XML streams using declarative COBOL file verbs (ORGANIZATION IS XML and XD descriptors), requiring compilation under the PREXML preprocessor directive ($SET P(PREXML) ENDP). [1] [2] [3] [4]

Read the full briefing

Scope and Architectural Overview

This article covers command-line schema generation, bi-directional XML mapping, and XML Syntax Extensions in Rocket Enterprise Developer / Enterprise Server 12.0 for Linux/UNIX.

While the procedural XML PARSE statement provides event-driven SAX parsing, Rocket Enterprise Developer also provides declarative XML Syntax Extensions. This facility allows COBOL programs to treat XML document streams as structured files, executing input and output operations through standard COBOL I/O verbs (OPEN, READ, WRITE, and CLOSE).

Generating the required metadata structures—including XML-enhanced copybooks with IDENTIFIED BY clauses, W3C XML Schema Definition (.xsd) files, and mapping definitions—is handled by the CBL2XML Utility.

The cbl2xml Utility and Command-Line Syntax

The cbl2xml utility is available strictly as a command-line tool. It supports three primary workflows:

  1. Converting an existing COBOL data description into an XML-enhanced copybook and an associated XML schema.
  2. Converting an external XML schema (.xsd) into an XML-enhanced COBOL copybook.
  3. Validating XML schemas and XML instance documents against W3C XML conventions.

The utility is invoked using the following syntax:

cbl2xml filename [-c cpyBook] [-x schemaFile] [-m mapFile] [-p prefix] [-d directiveFile] [-v validationFile] [-noprompt] [-nocountin] [-fixedfraction]

Key parameters include:

  • filename: The input file, specifying either a COBOL program/copybook (.cbl / .cpy) or an XML schema (.xsd).
  • -c cpyBook: Designates the name of the generated copybook (defaults to <filename>-cbl2xml.cpy).
  • -x schemaFile: Specifies the target schema file to generate (defaults to <filename>.xsd).
  • -p prefix: Prepends a string (such as xml-) to generated COBOL data names, keeping original application field identifiers intact.
  • -nocountin: Suppresses the generation of COUNT IN clauses on COBOL items.
  • -fixedfraction: Forces the schema fractionDigits facet to the exact number of fractional digits declared in the COBOL picture clause rather than the maximum.
  • -noprompt: Suppresses interactive confirmation prompts when overwriting files. Because -noprompt unconditionally overwrites all output artifacts, customized map files or supplier-provided schemas can be overwritten if output filenames collide.

Two-Stage Schema Mapping via .map Files

When integrating an existing COBOL data structure with an independently authored third-party XML schema, data-names and XML element names rarely align. As detailed in Mapping COBOL Data to XML Elements, cbl2xml resolves these discrepancies through an intermediate XML map file:

  1. Map Generation: Specifying a non-existent map filename (cbl2xml product.cpy -m product.map) causes cbl2xml to extract the COBOL record layout and generate an XML mapping document conforming to mfxmlmap.xsd.
  2. Map Customization: The map file contains <xml-cobol-mapping> tags pairing COBOL identifiers (<cobol-name>) with XML targets (<xml-name>, <xml-type>, <xml-attribute>, and <xml-namespace>). The developer modifies <xml-name> to match target schema element names (e.g., mapping prod-id to Product_Id). Setting <xml-attribute>true</xml-attribute> maps a field as an XML attribute rather than an element.
  3. Copybook Generation: Re-executing cbl2xml with the edited map file (cbl2xml product.cpy -m product.map) generates the final XML-enhanced copybook:
01 product-info identified by "Widgets"
   count in widgets-count.
   02 prod-id pic 9(6) identified by "Product_Id"
      count in Product_Id-count.
   02 company-id pic 9(4) identified by "Company_Id"
      count in Company_Id-count.

The Declarative I/O Model: ORGANIZATION IS XML and XD

As shown in Accessing an XML-enabled Record, once an XML-enhanced copybook is generated, the application references the XML stream in the Environment and Data Divisions using declarative file syntax:

$set p(prexml) endp
 select xml-stream assign "widgets.xml"
                   organization is xml
                   document-type is "widgets.xsd"
                   file status is file-status-spec.

 xd xml-stream.
    copy "widgets-cbl2xml.cpy".

 data division.
 working-storage section.
 01 file-status-spec pic s9(9).

 procedure division.
     open output xml-stream
     write widgets
     display file-status-spec
     close xml-stream
 stop run.

An XML file connector uses the XML Descriptor (XD) entry rather than a standard File Descriptor (FD). Writing to the record serializes working storage into formatted XML; reading from the stream parses inbound XML directly into the COBOL record layout.

Operational Nuances and Compilation Requirements

  • Preprocessor Obligation: As documented in Compiling XML-enabled COBOL, programs containing XML Syntax Extensions must be processed by the XML preprocessor. Omitting $SET P(PREXML) ENDP (or the compiler directive -C "P(PREXML)") causes compilation to fail with syntax errors on XD, IDENTIFIED BY, and ORGANIZATION IS XML.
  • Command-Line Exclusivity: cbl2xml operates solely as an external command-line executable and is not integrated into Eclipse IDE UI dialogs.
  • Validation Capabilities: Passing -v filename allows cbl2xml to validate schema definitions against W3C XML Schema standards or validate XML instance documents against their declared schemas prior to execution.

Documentation Takeaway

In Rocket Enterprise Developer 12.0 for Linux/UNIX, the cbl2xml utility bridges COBOL records and external XML schemas by generating XML-enhanced copybooks and schemas via customizable .map files; applications process XML streams declaratively using ORGANIZATION IS XML and XD file entries, which requires enabling the PREXML compiler preprocessor.

Rocket Enterprise Developer / Enterprise Server 12.0 for Linux/UNIX
Documentation references
That’s the briefing.You’ve reached the end of this edition.
More editions

From the archive

View all
Nov 4

The Communications Log: One Ever-Growing File by Default, Rotating Files via mf-server.dat

Nov 4

Fileshare Rollback Recovery: Faster, but Only with the Right Logging Guarantees

Nov 4

ESF Passtokens: A [Passtoken] allow= Switch, Per-User LDAP Rights, and Why MFDS and ESCWA Must Share One Security Configuration