Erga Kandly
Erga Kandly

Reputation: 799

COBOL XML GENERATE using tags and attributes

I am trying to create a XML file from a COBOL program using the XML GENERATE statement.

COBOL structure :

    01 EMPLOYEE.
       05 ID PIC X(1).
       05 NAME PIC X(10).
       05 DEPT PIC X(10).

XML GENERATE will create all sub elements

<employee>
  <id>1</id> 
  <name>Someone</name>
  <dept>Marketing</dept>
</employee>

If I use XML GENERATE WITH ATTRIBUTES Function, It will create all attributes :

<employee id="1" name="Someone" dept="Marketing"> 
</employee>

Is there a way we can somehow indicate that some sub group items should be attributes and some sub elements:

<employee id="1">
  <name>Someone</name>
  <dept>Marketing</dept>
</employee>

and if yes, how?

Upvotes: 3

Views: 2019

Answers (1)

Simon Sobisch
Simon Sobisch

Reputation: 7297

Is there a way we can somehow indicate that some sub group items should be attributes and some sub elements

Answer: yes.

See IBM's docs on XML GENERATE statement, you can adjust the type of a single data-item with the TYPE phrase, which may specify multiple items:

           XML GENERATE variable-name
               FROM EMPLOYEE
               TYPE OF ID                 IS ATTRIBUTE
                       secondary-variable IS ATTRIBUTE

Note: as IBM's docs XML element name and attribute name formation says:

The exact mixed-case spelling of data-names from the data description entry is retained.

You likely want to change the COBOL variable names to all lower case or use the NAME phrase for all data-entries (at least if you expect it to be all in lower case as in your "target sample").

Upvotes: 5

Related Questions