C$XML
The C$XML routine allows you to deal with XML documents. It allows you to parse documents and change their content as well as create new documents from scratch.
When parsing the XML document, referenced DTD (Document Type Definition) and XSD (XML Schema definition) are considered. If the referenced DTD can’t be found due to invalid or unreachable location, then it’s ignored.
When writing content to the XML document, the following data conversion rules are applied:
Text is encoded using the character set specified by the iscobol.encoding * property
Trailing spaces in alphanumeric parameters are trimmed
Leading zeros are kept in numeric values
Syntax:
 CALL "C$XML" USING opCode 
                    parameters
             GIVING returnCode
Parameters:
opCode
Is the function to be executed. Valid values, defined in ..., are:
 
Opens a XML file and returns the XML tree
 
Releases memory used by the XML tree
 
Returns the first child of a given element
 
Returns the next sibling of a given element
 
Returns the parent element of a given element
 
Returns the name and the CDATA of a given element
 
Returns the number of attributes of a given element
 
Returns the name and the value of a given attribute
 
Returns the last error
 
Opens a XML file without parsing it
 
Parses a string as XML
 
Parses the next record in the element
 
Returns the previous sibling of a given element
 
Creates an empty XML document in memory
 
Returns the attribute with the given name along with its value
 
Returns the child element with the given name
 
Returns the child element with the given CDATA
 
Returns the child element with the given attribute
 
Returns the child element with the given attribute value
 
Returns the sibling element with the given name
 
Returns the sibling element with the given CDATA
 
Returns the sibling element with the given attribute
 
Returns the sibling element with the given attribute value
 
Returns the comment associated to a given element or document
 
Changes the CDATA of a given element
 
Changes the value of a given attribute
 
Adds a new child item to the given element
 
Adds a new sibling item to the given element
 
Adds an attribute to a given element
 
Adds a comment to a given element or document
 
Appends a new comment to a given element or document
 
Deletes an attribute from an element
 
Deletes an element
 
Deletes comments from an element
 
Writes a XML document to file
 
Writes a String
 
Retrieves the number of processing instructions
 
Retrieves processing instructions
 
Sets processing instructions
 
Returns the version of the XML document
 
Changes the version of the XML document
 
Returns the encoding of the XML document
 
Changes the encoding of the XML document
 
Returns the value of the standalone pseudo-attribute
 
Changes the value of the standalone pseudo-attribute
Return code:
The definition and meaning of the returnCode depend on the opcode.
Examples:
Example - Read the content of file.xml and show it on the console.
       working-storage section.
       copy "iscobol.def".
       
       77  xml-handle                          handle.
       77  elem-handle                         handle.
       77  next-elem-handle                    handle.
       77  xml-item-name                       pic x(32).
       77  xml-item-value                      pic x(32).
       77  attr-count                          pic 99.
       77  i                                   pic 99.
       77  attr-name                           pic x(32).
       77  attr-value                          pic x(32).
       
       procedure division.
       read-xml.
           call "c$xml" using cxml-parse-file
                              "file.xml"
                       giving xml-handle.
                       
           call "c$xml" using cxml-get-first-child
                              xml-handle
                       giving elem-handle.
                                          
           perform until exit
             initialize xml-item-name, xml-item-value
             call "c$xml" using cxml-get-data
                                elem-handle
                                xml-item-name
                                xml-item-value
             display "elem. name: " xml-item-name
             display "elem. value: " xml-item-value
                                
             call "c$xml" using cxml-get-attribute-count
                                elem-handle
                         giving attr-count       
             display "attr. count: " attr-count
             if attr-count > 0
                perform varying i from 1 by 1 until i > attr-count
                  call "c$xml" using cxml-get-attribute
                                     elem-handle
                                     i
                                     attr-name
                                     attr-value
                  display "attr. name: " attr-name
                  display "attr. value: " attr-value
                end-perform
             end-if
             call "c$xml" using cxml-get-next-sibling 
                                elem-handle
                         giving next-elem-handle
             destroy elem-handle
             if next-elem-handle = 0
                exit perform
             else
                move next-elem-handle to elem-handle
             end-if
           end-perform.
           display ""
           call "c$xml" using cxml-release-parser
                              xml-handle.
           accept omitted.
           goback