Enterprise COBOL XML Attributes

15 pts.
Tags:
COBOL
XML
XML GENERATE
XML Generator Package
z/OS
I am working on a COBOL XML Application where the XML message needs to have an attribute on the Group Level, with subordinate items generated as Child elements. According to the Enterprise COBOL manuals, it appears that I can choose EITHER format by specifing WITH ATTRIBUTES on the XML GENERATE Statement. In my situation, I would like to do both in the same structure. I would like the structure to format with child elements, but also provide an attribute on the Group Level tag. Example: 01 C-Type PIC X(10). 88 New -Customer VALUE 'NEW' 88 Existing-Customer VALUE 'EXISTING' 01 XML-DOC PIC X(512). 01 Customer. 05 Name PIC X(20). 05 Address PIC X(20) 05 City PIC X(20) 05 State PIC X(02) 05 Zip PIC X(05). <== desired XML output ====> <Customer C-Type = "NEW"> <Name>JOHN SMITH</Name> <Address>123 Main St.</Address> <City>Springdale</City> <State>MI</State> <Zip>41111</Zip> </Customer> <=======================> If I code a standard XML GENERATE, then I would get the desired structure, however it would not contain the attribute on the <Customer> tag: XML GENERATE XML-DOC from Customer <Customer> <Name>JOHN SMITH</Name> <Address>123 Main St.</Address> <City>Springdale</City> <State>MI</State> <Zip>41111</Zip> </Customer> If I code the XML GENERTATE WITH ATTRIBUTES, then the output would be: Ex: XML GENERATE XML-DOC from Customer WITH ATTRIBUTES <Customer Name="JOHN SMITH" Address="123 Main St." City=Springdale" State="MI" Zip=41111></Customer> Is there a way to combine the formats to cause a specific field to show as an attribute of a tag, while others generate as child segments?

Answer Wiki

Thanks. We'll let you know when a new response is added.

One way I have found to make this work is by using an occurs of 1 on fields that you want to be generated as child elements. So the example used in this question would look like this.

01 Customer.
05 C-Type PIC X(10).
05 Name occurs 1 PIC X(20).
05 Address occurs 1 PIC X(20)
05 City occurs 1 PIC X(20)
05 State occurs PIC X(02)
05 Zip occurs 1 PIC X(05).

You then use the with attributes option in your xml generate. Elements with an occurs clause do not generate as attributes. The only drawback to this solution is that you have to use a subscript whenever you use one of the fields with a occurs clause.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following