XML Read Example

A simple example demonstrating how to parse XML files

An example showing how to use the XML praser built into the API.

The example script reads the file ‘Read.xml’ – this is a simplified version of what can be outputted from the ‘Read.xlsx’ spreadsheet.
The script is illustrating how to set up XML parser handlers and callback functions:

First a user-defined object (dataobj) is set up to store information in the xml file (note: if large XML files are being called then this method of storing temporary data might not be the best approach due to memory limits).
dataobj.rowcount is used to determine the number of rows. +1 will be added after row element end is found.
dataobj.i is a variable that “lags” behind rowcount to determine changes in the number of row count.
dataobj.data is a boolean to determine if the current element is “Data” element or not. Only if dataobj.data = = true, information will be stored.
dataobj.row_string is a variable storing one line as a string (as one line would be in Excel when opening the XML file).
dataobj.txt_row is an array storing row_string variables. The array is used to store the strings for writing a txt file.

The script will output a text file replicating data found in XML file.