XML Generation

The XML.GENERATE subroutine allows you to convert Reality data into XML format. You must supply an XML template into which to insert the data and a dynamic array containing the data to be converted. The result is a string, returned in a variable you supply, that can be saved in a host file using a directory view or sequential file access.

For example, if the variable RDATA is a dynamic array containing the data to be converted to XML and XMLTEMP is a string containing an XML template, you would call XML.GENERATE as follows:

CALL XML.GENERATE(EMSG, XMLDOC, XMLTEMP, RDATA)

On return, XMLDOC will contain the required XML document and EMSG will normally be an empty string (if an error occurred, EMSG would contain an appropriate error message).

Writing an XML Template

An XML template is an XML document that contains markers that show where the Reality data is to be inserted. These markers are of two types:

Data markers These have the format SVMattrNo{,valueNo{,subvalueNo}}SVM (where SVM represents a subvalue mark). They specify the data, extracted from the dynamic array, to be inserted at this point.

Option markers These are sections of text enclosed in value marks (VM). The enclosed text is optional – if all the data markers within the enclosed text evaluate to null, the text is omitted from the result (the text is also omitted if it contains no data markers). Note that option markers cannot be nested.

For example,

<jaws>
<type-mappings>
<type-mapping-definition>
<name>SVM1SVM</name>
<mapping>
<java-type>SVM2,1SVM</java-type>
VM <jdbc-type>SVM2,2SVM</jdbc-type>VM
</mapping>
</type-mapping-definition>
</type-mappings>
</jaws>

In this example, the contents of attribute 1 of the dynamic array are inserted into the <name>  node, attribute 2, value 1 into the <java-type>  node and attribute 2, value 2 into the <jdbc-type>  node. The line containing the <jdbc-type>  node is enclosed in value marks and is therefore optional – if attribute 2, value 2 evaluates to null, this line will be omitted.

Processing Options

If you are preparing your template with an editor that does not support inserting Reality value and subvalue marks, you can change the characters used to delimit Data and Option markers. Include, as the first node in your template, an XML node with the following format:

<__nis_cont {paramDelim="string1"} {optionalDelim="string2"}/>

where string1 and string2 are single characters or sequences of characterss that do not appear elsewhere in the template. For example, the following template uses percent signs (%) as Data Marker delimiters and dollar signs ($) as Option Marker delimiters.

<__nis_cont paramDelim="%"optionalDelim="$"/>
<jaws>
   <type-mappings>
      <type-mapping-definition>
         <name>%1%</name>
         <mapping>
            <java-type>%2,1%</java-type>
$            <jdbc-type>%2,2%</jdbc-type>$
         </mapping>
      </type-mapping-definition>
   </type-mappings>
</jaws>

Examples

The topic XML Generation Examples shows various XML templates and typical results.

Go to top button