Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not generate empty xml attributes

First, let me apologize if I use wrong vocabulary, as I'm not too familiar with COBOL. We are trying to generate xml documents from a fixed data structure in COBOL. This is working well, using the GENERATE statement, but we have an issue.

If the data is the following:

First;Second;Age;Optional
JOHN;SNOW;18;Something
JOHN;DOE;45;Nothing
JOHN;ISSUE;30;

Then the generated xml looks like this:

<Persons>
   <Person First="JOHN" Second="SNOW" Age="18" Optional="Something"/>
   <Person First="JOHN" Second="DOE" Age="45" Optional="Nothing"/>
   <Person First="JOHN" Second="ISSUE" Age="18" Optional=""/>
</Persons>

When we would like the generator not to create the attributes when they have an empty value:

<Persons>
   <Person First="JOHN" Second="SNOW" Age="18" Optional="Something"/>
   <Person First="JOHN" Second="DOE" Age="45" Optional="Nothing"/>
   <Person First="JOHN" Second="ISSUE" Age="18" />
</Persons>

Is there an easy way to acheive this ? Been looking around in IBM documentation and on google, with no luck.

like image 594
user1771658 Avatar asked Mar 28 '26 18:03

user1771658


1 Answers

We have had success using OCCURS 0 to 1 DEPENDING var for optional items. We set var to 0 or 1 depending on whether the referent exists.

It's a kludge. There is an extant SHARE requirement to make the kludge unnecessary; I expect the functionality is in the v.Next COBOL compiler.

like image 153
cschneid Avatar answered Mar 30 '26 12:03

cschneid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!