Initializing help system before first use

xmlparse

Purpose
Parse an XML document.
Synopsis
function xmlparse(afct:array(range) of string|function,mode:integer,ctx:ctxtype): integer
Arguments
afct 
Event function table. Each entry of this array is the name of or a reference to the function to call when the corresponding event occurs. The expected events are (all of these entries are optional):
XML_FCT_DECL 
Document declarations
XML_FCT_TXT 
A text node (same value as ML_TEXT)
XML_FCT_CDATA 
A CDATA node
XML_FCT_COM 
A commentary node
XML_FCT_DATA 
A DATA node
XML_FCT_PINST 
A processing instruction node
XML_FCT_OPEN_ELT 
Opening of a new element node
XML_FCT_CLOSE_ELT 
Closing of an element node
mode 
If 0, spaces are preserved and returned as text elements. Otherwise all text elements are trimmed
ctx 
Value passed as first argument of all event functions
Return value
0 if successful, 1 in case of parsing error or a non-zero value returned by an event function
Example
This example displays the structure of an XML document without loading it into memory.
! Display element name and update indentation
public function start_elt(spce:text,name:text,nba:integer):integer
 writeln(spce,name)
 spce+="  "
end-function

! Update indentation when element closes
function end_elt(spce:text):integer
 spce-="  "
end-function

declarations
 afct:array(range) of any
end-declarations

afct(XML_FCT_OPEN_ELT):="start_elt" ! define open element
afct(XML_FCT_CLOSE_ELT):=->end_elt  ! define close element
fopen("mydocument.xml",F_INPUT)
rts:=xmlparse(afct,1,text(""))
fclose(F_INPUT)
Further information
1. This function is an alternative approach to load for processing XML documents: instead of loading into memory the entire document this function calls a dedicated routine whenever it identifies an XML entity. For instance a specific function is called when an element is open and another one when it is closed. It is up to the Mosel program to decide how to handle the document via these event handling functions.
2. To each event type corresponds a specific function signature. These functions return an integer that decides whether parsing should continue: a non-zero value will cause the parsing to cancel (this value is used as the return value of xmlparse). The expected function signatures are:
XML_FCT_DECL
function xmldecl(ctx:ctxtype, vers:text, enc:text, std:integer):integer
XML_FCT_TXT
function text_node(ctx:ctxtype, type:integer, data:text):integer
XML_FCT_CDATA
function cdata_node(ctx:ctxtype, type:integer, data:text):integer
XML_FCT_COM
function comment_node(ctx:ctxtype, type:integer, data:text):integer
XML_FCT_DATA
function data_node(ctx:ctxtype, type:integer, data:text):integer
XML_FCT_PINST
function processing_instr(ctx:ctxtype, target:text, data:text):integer
XML_FCT_OPEN_ELT
function open_element(ctx:ctxtype, name:text, nba:integer):integer
XML_FCT_CLOSE_ELT
function close_element(ctx:ctxtype):integer
In addition to the pre-defined arguments these functions take a context as their first parameter. This variable (that can be of any type) is provided to the xmlparse routine and can be used by the event functions for storing progress information.
The type passed to the text node functions is the XML type corresponding to the function (namely XML_TXT, XML_CDATA, XML_COM, XML_DATA).
The open_element function receives the name of the element as well as the number of defined attributes. To retrieve these attributes xmlattr can be used.
3. An error message indicating the location of the error is displayed when the parsing fails or if an event function returns a negative value (a positive value also interrupts parsing but no message is displayed).
Related topics
Module

© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.