Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COBOL XML GENERATE using tags and attributes

Tags:

cobol

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?

like image 762
Erga Kandly Avatar asked Jan 18 '26 13:01

Erga Kandly


1 Answers

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").

like image 171
Simon Sobisch Avatar answered Jan 21 '26 09:01

Simon Sobisch