XML Support
In V5R4, COBOL stays ahead of RPG in the area of XML support. COBOL learned
to read XML in V5R3, but RPG had to wait until V5R4. Now COBOL learns to
write XML.
The command to write XML is called XML GENERATE. It has two forms,
depending on whether you want to place the generated XML into a
variable or an IFS file. Here's an untested example that gives an
idea of how this works.
First, consider the following source code from the data and procedure divisions.
PHP Code:
Data division.
01 EmployeeRec.
03 Name pic X(25).
03 Badge pic S9(5).
03 MailAddress.
05 Street pic X(20).
05 City pic X(12).
05 State pic X(2).
03 Personal.
05 MaritalStatus pic X.
05 BirthDate pic X(8).
01 XMLMsg pic X(1000).
01 IFSFile pic x(50) value "/home/mydir/SomeIFSFile.xml".
Procedure division.
* Place the generated XML into a variable.
XML GENERATE XMLMsg
FROM EmployeeRec
END-XML.
* Place the generated XML into an IFS file.
XML GENERATE FILE-STREAM IFSFile
FROM EmployeeRec
END-XML.
EmployeeRec structure. The first XML GENERATE command stores the
XML in the XMLMsg variable. The second stores the XML in IFS file
SomeIFSFile.xml. In either case, the generated XML
looks something like this:
PHP Code:
<EmployeeRec>
<Name>Joe Smith</Name>
<Badge>12345</Badge>
<MailAddress>
<Street>101 Main St</Street>
<City>Lost Angeles</City>
<State>NY</State>
</MailAddress>
<Personal>
<MaritalStatus>M</MaritalStatus>
<BirthDate>19010203</BirthDate>
</Personal>
</EmployeeRec>
COUNT IN stores the number of generated XML characters in a variable.
ON EXCEPTION and NOT ON EXCEPTION allow the programmer to include
code that is to be executed if the XML generation fails or succeeds.
After XML GENERATE executes, you may check the XML-CODE special
register to determine failure or success. A value of zero means that the
generation was successful.
Comment