there areand - and/or
tags present, the database can be read,
displayed and searched through.
The parse() function in parse2.inc invokes a series of in built XML related functions in
PHP. The coder creates two functions to define exactly what should happen when the
parser meets either an opening XML tag or a closing one. The function for an opening
tag, in this case called startElement(), must always take the handle of the XML parser
($parser), the name of the tag ($name) and the associative array of attributes ($attribs[])
as parameters. The corresponding closing tag function (endElement()) takes only the
parser and the tag name as attributes. For the purposes of this system, endElement() did
absolutely nothing at all, our only concern being with tag names and attributes.
When startElement() comes across a tag called either SERVICE, ITEM or SHOP, it
pushes the attributes of that tag onto a global array called $shopsarray[]. It is the parser
engine, incidentally, that automatically capitalises the attribute names it proves to be
convenient later on when displaying the names in a search panel on the left. Once each
shop has been run through, the $shopsarray[] of our example shops will look something
like this:
Array(
[0] => Array(
[BIZNAME] => Killian Computer Software Engineers
)
[1] => Array(
[DESC] => laptop
[MAKE] => Toshiba
[MODEL] => Satellite
[PRICE] => 1599
)
[2] => Array(
[DESC] => laptop
[MAKE] => HP
[MODEL] => Omnibook
[PRICE] => 2105
[COLOUR] => blue
41