Previous Topic Next topic Print topic


XML Implementation

XML data encoding is record-based and the vast majority of possible encodings can be easily represented as COBOL data records. For example, this XML stream:

<?xml version="1.0"?>
<group elementNumber=1235 >
   <elementAlpha>Alpha value</elementAlpha>
</group>

Can be received directly by COBOL code using syntax extensions as follows:

01  xmls-group                    identified by "group".
    05  xmls-Number     pic 9(18) identified by 
        "elementNumber" is attribute.
    05  xmls-Alpha      pic x(80) identified by 
        "elementAlpha".

This is a simple example. However, we support a number of more complex syntax scenarios, including variable tag specifications, non-regular and nested occurrences, mixed data, and optional elements.

Once you are able to encode XML records in your application, you can originate or receive these records in your COBOL application. Do this using standard file input/output verbs including OPEN, READ, WRITE, and CLOSE. The run-time support automatically converts, encodes, and performs all of the necessary I/O. For example, the following code is all that is necessary to generate the XML stream depicted in the example above into the file out.xml:

$set preprocess(prexml) endp    
 select xml-stream assign "out.xml"
           organization  is xml   
           document-type is "group"
           file status is xml-bookdb-status.
     xd xml-stream.
     01  xmls-group                identified by "group".
         05  xmls-Number pic 9(18) 
             identified by "elementNumber" is attribute.
         05  xmls-Alpha  pic x(80) 
             identified by "elementAlpha".
     working-storage section.
     01  xml-bookdb-status         pic s9(9) comp.
 
     move 1235                     to xmls-Number
     move "Alpha value"            to xmls-Alpha
     open output xml-stream
     write xmls-group
     close xml-stream
     stop run.
Previous Topic Next topic Print topic