xmlreader class

xmlreader class A simple XML document parser
Inherits
object
Description
This class implements a really simple XML document parser. You will usually derive your own class from this one and reimplement some of the events that it triggers. You will typically reimplement $onelementstart() and $onelementend() that will be called during the execution of $parse() in an order reflecting the order of elements in the parsed document.
Functions
`<boolean> $parse(<xml_data:string_or_memorybuffer_object>)`
Call this function to parse a string that contains an XML document. A typical call for this method will look like: %x = $new(xmlreader) %x->$parse($file.read("/home/somefile.xml")) During the call the <xml_data> string will be parsed and the relevant on* events (see below) will be triggered. $parse will return $true when the parsing terminates successfully or $false if it aborts for some reason (unrecoverable error in the document, user abort etc.). If this function return $false then you can call $lastError() to obtain a descriptive error message.
`<string> $lastError()`
Returns the last error occurred inside the parser. You will typically call this function when $parse() above returns $false.
`<boolean> $onDocumentStart()`
This function is called when the document parsing starts. You can reimplement it in order to handle this notification. You should return $true if you want document parsing to continue and $false if you want it to be aborted. The default implementation does nothing besides returning $true.
`<boolean> $onDocumentEnd()`
This function is called when the document parsing terminates successfully. You can reimplement it in order to handle this notification. You should return $true if you want document parsing to continue and $false if you want it to be aborted. The default implementation does nothing besides returning $true.
`<boolean> $onElementStart(<qualified_name:string>,<attributes:hash>,<namespace:string>,<local_name:string>)`
This function is called when an element opening tag is encountered. The <qualified_name> of the tag is passed as the first parameter. The <attributes> are passed in the form of a hash with attribute values indexed by their names. When the <qualified_name> contains a namespace then it is also reported in the split <namespace> <local_name> pair. You should return $true if you want document parsing to continue and $false if you want it to be aborted. The default implementation does nothing besides returning $true.
`<boolean> $onElementEnd(<qualified_name:string>,<namespace:string>,<local_name:string>)`
This function is called when an element closing tag is encountered. The <qualified_name> of the tag is passed as the first parameter. When the <qualified_name> contains a namespace then it is also reported in the split <namespace> <local_name> pair. You should return $true if you want document parsing to continue and $false if you want it to be aborted. The default implementation does nothing besides returning $true.
`<boolean> $onText($0 = <text:string>)`
This function is called when a chunk of text is encountered inside the document. The parsed <text> chunk is passed as the first parameter. You should return $true if you want document parsing to continue and $false if you want it to be aborted. The default implementation does nothing besides returning $true.
`<boolean> $onWarning(<message:string>)`
This function is called when the parser generates a recoverable error. The error <message> is passed as the first parameter. You should return $true if you want document parsing to continue and $false if you want it to be aborted. The default implementation does nothing besides returning $true.
`<boolean> $onError(<message:string>)`
This function is called when the parser generates an unrecoverable error. The error <message> is passed as the first parameter. The document parsing can't continue. The default implementation does nothing besides returning $true.

Index, Object Classes