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?
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").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With