Modes

Modes

Modes -- Explanation of possible parsing modes

Parser modes of XML_Parser

XML_Parser provides two modes for parsing:

  • func

  • event

In the 'event' mode, XML_Parser will always call the methods startHandler() and endHandler(), independent of the tag name. In these methods you'll have to check for tha tagname which, is passed as the second parameter and decide what you need to do. In most cases, this is done with a switch/case statement.

In the 'func' mode, XML_Parser will call different methods based on the name of the tag. This allows you to dispatch different tags to different methods. The methods to handle the start tag have to be called xmltag_[tagname](), where [tagname] has to be substituted by the name of the element that you wish to process. That means if you wish to write a method to process all opening <title> tags, it has to be called xmltag_title.

Methods to handle closing tags have to be named xmltag_[tagname]_() (distinguishes from the start element handler using a traling underscore).

If a method does not exist, XML_Parser will skip the tag without handling the element.

Setting the mode

There are two ways of setting the mode:

  • Specifying the mode in the constructor as the second parameter.

    In the subclass of XML_Parser that you implemented to process the XML documents, you will have to call XML_Parser::XML_Parser() in the constructor. This method accepts the mode as its second parameter.

  • Setting the mode using XML_Parser::setMode().

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.