Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of XML GENERATE and empty fields

Status
Not open for further replies.

Yordaman

Technical User
Dec 18, 2000
27
GB
I'm using the XML GENERATE statement to convert a fixed-format data structure into XML. However, some of my data items in the structure are empty, and the conversion deals with this like so:-

01 addressArea.
05 addressLine1 PIC X(30).
05 addressLine2 PIC X(30).
05 addressLine3 PIC X(30).

MOVE '32 High Street' TO addressLine1
MOVE 'Lowtown' TO addressLine2

Only the first 2 address lines have data, the third is empty (spaces). The resulting XML string comes out as:-

<addressArea><addressLine1>32 High Street</addressLine1><addressLine2>Lowtown</addressLine2><addressLine3> </addressLine3></addressarea>

I wouldn't want to see the third address element like this - I'd have hoped to either see <addressLine3/> or for it not to be present at all.

Any ideas on how to handle the GENERATE statement that will give the desired results?
 
It may not be clear from the above, but there is a single space as the 'value' for <addressLine3> (the formatting of the thread content makes this hard to pick out).
 
And what happens if addressLine3 contains LOW-VALUES instead of SPACES ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ah, now there's another story. In short, LOW-VALUES doesn't work. In long, if XML GENERATE finds a field containing LOW-VALUES, even if one character of 30 is LOW-VALUES, it generates an XML string but (a) converts the content into hex, and (b) alters the element name to reflect that the content is in hex.

In the above example, if addressLine3 contained one or more LOW-VALUES characters, the generated string for that element would have been:-

<hex.addressLine3>000000000000000000000000000000000000000000000000000000000000</hex.addressLine3>

The content is the hex representation of the 30 bytes of LOW-VALUES, and it's also altered the element name.
 
This would be an obvious situation in which to use an XSLT stylesheet. Unfortunately, the GENERATE statement doesn't seem to allow the specification of a stylesheet. Can you postprocess the file? If so, a rather simple XSLT will do the trick nicely.

Tom Morrison
 
You're right, Tom, in that the mainframe doesn't offer up the same variety of function available in other environments - you've got a 'parse' and generate' function in COBOL, but nothing else along the lines of stylesheets, etc (at least not to my knowledge).

I have built my own post-processer that will recognise the peculiar output the generator produces and reformats it into something more acceptable, but I guess the point of my original post was to see if there was anything more formal that would be a better solution. It sounds like such a solution doesn't exist and people will have to allow for this when using these statements.

Thanks for your interest, though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top