Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/pear/XML/Parser/Simple.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
00004 
00053 require_once 'XML/Parser.php';
00054 
00096 class XML_Parser_Simple extends XML_Parser
00097 {
00104     var $_elStack = array();
00105 
00112     var $_data = array();
00113 
00120     var $_depth = 0;
00121 
00127     var $handler = array(
00128         'default_handler'                   => 'defaultHandler',
00129         'processing_instruction_handler'    => 'piHandler',
00130         'unparsed_entity_decl_handler'      => 'unparsedHandler',
00131         'notation_decl_handler'             => 'notationHandler',
00132         'external_entity_ref_handler'       => 'entityrefHandler'
00133     );
00134     
00148     function XML_Parser_Simple($srcenc = null, $mode = 'event', $tgtenc = null)
00149     {
00150         $this->XML_Parser($srcenc, $mode, $tgtenc);
00151     }
00152 
00159     function _initHandlers()
00160     {
00161         if (!is_object($this->_handlerObj)) {
00162             $this->_handlerObj = &$this;
00163         }
00164 
00165         if ($this->mode != 'func' && $this->mode != 'event') {
00166             return $this->raiseError('Unsupported mode given', 
00167                 XML_PARSER_ERROR_UNSUPPORTED_MODE);
00168         }
00169         xml_set_object($this->parser, $this->_handlerObj);
00170 
00171         xml_set_element_handler($this->parser, array(&$this, 'startHandler'), 
00172             array(&$this, 'endHandler'));
00173         xml_set_character_data_handler($this->parser, array(&$this, 'cdataHandler'));
00174         
00178         foreach ($this->handler as $xml_func => $method) {
00179             if (method_exists($this->_handlerObj, $method)) {
00180                 $xml_func = 'xml_set_' . $xml_func;
00181                 $xml_func($this->parser, $method);
00182             }
00183         }
00184     }
00185 
00195     function reset()
00196     {
00197         $this->_elStack = array();
00198         $this->_data    = array();
00199         $this->_depth   = 0;
00200         
00201         $result = $this->_create();
00202         if ($this->isError($result)) {
00203             return $result;
00204         }
00205         return true;
00206     }
00207 
00221     function startHandler($xp, $elem, &$attribs)
00222     {
00223         array_push($this->_elStack, array(
00224             'name'    => $elem,
00225             'attribs' => $attribs
00226         ));
00227         $this->_depth++;
00228         $this->_data[$this->_depth] = '';
00229     }
00230 
00243     function endHandler($xp, $elem)
00244     {
00245         $el   = array_pop($this->_elStack);
00246         $data = $this->_data[$this->_depth];
00247         $this->_depth--;
00248 
00249         switch ($this->mode) {
00250         case 'event':
00251             $this->_handlerObj->handleElement($el['name'], $el['attribs'], $data);
00252             break;
00253         case 'func':
00254             $func = 'handleElement_' . $elem;
00255             if (strchr($func, '.')) {
00256                 $func = str_replace('.', '_', $func);
00257             }
00258             if (method_exists($this->_handlerObj, $func)) {
00259                 call_user_func(array(&$this->_handlerObj, $func), 
00260                     $el['name'], $el['attribs'], $data);
00261             }
00262             break;
00263         }
00264     }
00265 
00276     function cdataHandler($xp, $data)
00277     {
00278         $this->_data[$this->_depth] .= $data;
00279     }
00280 
00294     function handleElement($name, $attribs, $data)
00295     {
00296     }
00297 
00306     function getCurrentDepth()
00307     {
00308         return $this->_depth;
00309     }
00310 
00321     function addToData($data)
00322     {
00323         $this->_data[$this->_depth] .= $data;
00324     }
00325 }
00326 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations