XML Support
XML is supported via the %XML function. XML can be in any file type. The *XML file type is intended for files that consist entirely of XML.
*XML File Type
File type *XML initially treats the returned data as a single chunk of XML, regardless of how the data is structured or how many physical file records in which it is actually contained.
With *XML you do not define file types, instead you define the whole record type, with no Start Position or Length. With files that contain a mix of XML and normal fields, or multiple but independent XML fields you must use one of the *FIXED, *HYBRID, or *CSV file type formats rather than *XML.
There are two important limits when working with the *XML file type:
Data length limit
The total length of the data must not exceed 16,776,704 bytes. This is the amount of data that a user space can store. If the data exceeds this length it cannot be processed.
Logical record length limit
Log File Monitor processes the XML data as one or more logical records. These records are defined by the Primary Tag. This defaults to *FIRST. In many cases, the first tag only occurs once, in which case there is only one logical record which comprises the entire XML data. However, multiple occurrences are possible. The maximum length of a logical record is 32,766 bytes. This is due to the maximum field length in the RPG programming language. A lot of XML data will exceed this limit and therefore cannot be monitored using the default settings. You must reduce the logical record length to 32,766 bytes or less. There are two techniques that you can use to achieve this:
- Break the XML data down into multiple but smaller logical records. Whether or not you are able to do this depends on your data and how to intend to process it.
- Filter out parts of the XML data that are not relevant to the check you need to perform
Example XML data:
The following is an example of XML data and extraction methods:
<?xml version="1.0" encoding="UTF-8"?><data type=”jobs” count=”3”><job name=”QPADEV0001” user=”TOM” nbr=”123456”/><job name=”QPADEV0001” user=”JOHN” nbr=”123457”/><job name=”QPADEV0001” user=”HARRY” nbr=”123458”/></data>
With the Primary Tag set to "DATA", Log File Monitor would see one logical record in this data:
1: <data type=”jobs” count=”3”><job name=”QPADEV0001” user=”TOM” nbr=”123456”/><job name=”QPADEV0001” user=”JOHN” nbr=”123457”/><job name=”QPADEV0001” user=”HARRY” nbr=”123458”/></data>
But with the Primary Tag set to "JOB", Log File Monitor would see the same data as three logical records:
1: <job name=”QPADEV0001” user=”TOM” nbr=”123456”/>
2: <job name=”QPADEV0001” user=”JOHN” nbr=”123457”/>
3: <job name=”QPADEV0001” user=”HARRY” nbr=”123458”/>
If the logical record length is still too long, you can try filtering out any tags and attributes that you do not need to check. You can do this using F20 Additional Options. For example, if you add a filter of "job/nbr" the three records shown above have the nbr tag removed:
1: <job name=”QPADEV0001” user=”TOM”/>
2: <job name=”QPADEV0001” user=”JOHN”/>
3: <job name=”QPADEV0001” user=”HARRY”/>
When a particular Tag is defined as the Primary Tag, you can still access attribute values from higher level tags. To do this, use the %XML function with the *CTLDTA specified as the XML data. For example, with the Primary Tag set to DATA:
<data type=”jobs” count=”3”><job name=”QPADEV0001” user=”TOM” nbr=”123456”/><job name=”QPADEV0001” user=”JOHN” nbr=”123457”/><job name=”QPADEV0001” user=”HARRY” nbr=”123458”/></data>
To get the value of the TYPE attribute (for example, "jobs") use:
%XML(&XMLDATA,’Data’,’Type’)
But with Primary Tag set to JOB, this information is no longer contained in any of the logical records:
<job name=”QPADEV0001” user=”TOM” nbr=”123456”/>
<job name=”QPADEV0001” user=”DICK” nbr=”123457”/>
<job name=”QPADEV0001” user=”HARRY” nbr=”123458”/>
But it still can be retrieved using:
%XML(*CTLDTA,’Data’,’Type’)
When *CTLDTA is used, you must define specific Tag and Attribute names. The value returned is the previous occurrence of that value in the XML data relative to the logical record being processed.