tags:

views:

411

answers:

3

Is it possible to use XML GENERATE to create XML with multi-level nested elements of different sizes?

For example:

01  SOURCE-REC.
    05  REPEATING-PARENT OCCURS 5 TIMES.
        10  PARENT-NAME PIC X(7).
        10  CHILD-COUNT PIC 9.
        10  REPEATING-CHILD OCCURS 1 TO 5 TIMES
                DEPENDING ON CHILD-COUNT.
            15  CHILD-NAME PIC X(6).

Compiling this using Enterprise Cobol v4.1 yields:

IGYGR1263-S "OCCURS DEPENDING ON" object "CHILD-COUNT" was defined as a table element. The "DEPENDING ON" phrase was discarded.

IGYGR1116-S The "DEPENDING ON" object for table "REPEATING-CHILD" was invalid. The "DEPENDING ON" phrase was discarded.

Not all parents are going to have the same number of children. How can this be addressed?

Edit: I suppose at its heart, this isn't really an XML question. I hit a wall just trying to build the working storage that I later hope to feed into XML GENERATE.

A: 
NealB
That's the heart of the problem I'm trying to solve. The number of children is different per parent. Parent 1 might have 3 children. Parent 2 might have 1 child. Sorry if that wasn't clear.
Basically, you can't do that because your original record definition is not a valid "complex ODO" record structure, see: http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/IGY3PG31/APPENDIX1.2.1?DT=20060329003636#HDRWQ1859
NealB
A: 

I think you should lose the DEPENDING ON altogether. It doesn't save memory, and you can just as easily address valid REPEATING-CHILD items by making sure their subscripts are in the range from 1 to the corresponding CHILD-COUNTER.

Albert Visser
The problem I have with this solution is that XML GENERATE will still create nodes in the XML for unpopulated children. This parent/child example is very simple with only two levels and a couple elements. The data I'm actually working with is much larger and the impact of outputting empty elements is huge.
yeah I was afraid of that. I don't know the XML Generate option that well, mostly know *of* it - at my company we have to let a web message broker turn fixed records into XML - but it makes sense for an automated solution
Albert Visser
A: 
NealB