⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml_htmlsax.php

📁 是一个教学内容管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4: *///// +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2002 The PHP Group                                |// +----------------------------------------------------------------------+// | This source file is subject to version 2.02 of the PHP license,      |// | that is bundled with this package in the file LICENSE, and is        |// | available at through the world-wide-web at                           |// | http://www.php.net/license/3_0.txt.                                  |// | If you did not receive a copy of the PHP license and are unable to   |// | obtain it through the world-wide-web, please send a note to          |// | license@php.net so we can mail you a copy immediately.               |// +----------------------------------------------------------------------+// | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |// | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more  |// | Authors: Many @ Sitepointforums Advanced PHP Forums                  |// +----------------------------------------------------------------------+//// $Id: XML_HTMLSax.php 2291 2004-11-16 19:35:41Z joel $///*** Main parser components* @package XML_HTMLSax* @version $Id: XML_HTMLSax.php 2291 2004-11-16 19:35:41Z joel $*//*** Required classes*/require_once(AT_INCLUDE_PATH.'classes/XML/XML_HTMLSax/PEAR.php');if (!defined('XML_HTMLSAX')) {    define('XML_HTMLSAX', AT_INCLUDE_PATH . 'classes/XML/XML_HTMLSax/'); /*  'XML/' had to be removed to work. joel/ATRC */}require_once(XML_HTMLSAX . 'HTMLSax/XML_HTMLSax_States.php');require_once(XML_HTMLSAX . 'HTMLSax/XML_HTMLSax_Decorators.php');/*** Base State Parser* @package XML_HTMLSax* @access protected* @abstract*/class XML_HTMLSax_StateParser {    /**    * Instance of user front end class to be passed to callbacks    * @var XML_HTMLSax    * @access private    */    var $htmlsax;    /**    * User defined object for handling elements    * @var object    * @access private    */    var $handler_object_element;    /**    * User defined open tag handler method    * @var string    * @access private    */    var $handler_method_opening;    /**    * User defined close tag handler method    * @var string    * @access private    */    var $handler_method_closing;    /**    * User defined object for handling data in elements    * @var object    * @access private    */    var $handler_object_data;    /**    * User defined data handler method    * @var string    * @access private    */    var $handler_method_data;    /**    * User defined object for handling processing instructions    * @var object    * @access private    */    var $handler_object_pi;    /**    * User defined processing instruction handler method    * @var string    * @access private    */    var $handler_method_pi;    /**    * User defined object for handling JSP/ASP tags    * @var object    * @access private    */    var $handler_object_jasp;    /**    * User defined JSP/ASP handler method    * @var string    * @access private    */    var $handler_method_jasp;    /**    * User defined object for handling XML escapes    * @var object    * @access private    */    var $handler_object_escape;    /**    * User defined XML escape handler method    * @var string    * @access private    */    var $handler_method_escape;    /**    * User defined handler object or NullHandler    * @var object    * @access private    */    var $handler_default;    /**    * Parser options determining parsing behavior    * @var array    * @access private    */    var $parser_options = array();    /**    * XML document being parsed    * @var string    * @access private    */    var $rawtext;    /**    * Position in XML document relative to start (0)    * @var int    * @access private    */    var $position;    /**    * Length of the XML document in characters    * @var int    * @access private    */    var $length;    /**    * Array of state objects    * @var array    * @access private    */    var $State = array();    /**    * Constructs XML_HTMLSax_StateParser setting up states    * @var XML_HTMLSax instance of user front end class    * @access protected    */    function XML_HTMLSax_StateParser (& $htmlsax) {        $this->htmlsax = & $htmlsax;        $this->State[XML_HTMLSAX_STATE_START] =& new XML_HTMLSax_StartingState();        $this->State[XML_HTMLSAX_STATE_CLOSING_TAG] =& new XML_HTMLSax_ClosingTagState();        $this->State[XML_HTMLSAX_STATE_TAG] =& new XML_HTMLSax_TagState();        $this->State[XML_HTMLSAX_STATE_OPENING_TAG] =& new XML_HTMLSax_OpeningTagState();        $this->State[XML_HTMLSAX_STATE_PI] =& new XML_HTMLSax_PiState();        $this->State[XML_HTMLSAX_STATE_JASP] =& new XML_HTMLSax_JaspState();        $this->State[XML_HTMLSAX_STATE_ESCAPE] =& new XML_HTMLSax_EscapeState();    }    /**    * Moves the position back one character    * @access protected    * @return void    */    function unscanCharacter() {        $this->position -= 1;    }    /**    * Moves the position forward one character    * @access protected    * @return void    */    function ignoreCharacter() {        $this->position += 1;    }    /**    * Returns the next character from the XML document or void if at end    * @access protected    * @return mixed    */    function scanCharacter() {        if ($this->position < $this->length) {            return $this->rawtext{$this->position++};        }    }    /**    * Returns a string from the current position to the next occurance    * of the supplied string    * @param string string to search until    * @access protected    * @return string    */    function scanUntilString($string) {        $start = $this->position;        $this->position = @strpos($this->rawtext, $string, $start);        if ($this->position === FALSE) {            $this->position = $this->length;        }        return substr($this->rawtext, $start, $this->position - $start);    }    /**    * Returns a string from the current position until the first instance of    * one of the characters in the supplied string argument    * @param string string to search until    * @access protected    * @return string    * @abstract    */    function scanUntilCharacters($string) {}    /**    * Moves the position forward past any whitespace characters    * @access protected    * @return void    * @abstract    */    function ignoreWhitespace() {}    /**    * Begins the parsing operation, setting up any decorators, depending on    * parse options invoking _parse() to execute parsing    * @param string XML document to parse    * @access protected    * @return void    */    function parse($data) {        if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) {            $decorator =& new XML_HTMLSax_Trim(                $this->handler_object_data,                $this->handler_method_data);            $this->handler_object_data =& $decorator;            $this->handler_method_data = 'trimData';        }        if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) {            $open_decor =& new XML_HTMLSax_CaseFolding(                $this->handler_object_element,                $this->handler_method_opening,                $this->handler_method_closing);            $this->handler_object_element =& $open_decor;            $this->handler_method_opening ='foldOpen';            $this->handler_method_closing ='foldClose';        }        if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) {            $decorator =& new XML_HTMLSax_Linefeed(                $this->handler_object_data,                $this->handler_method_data);            $this->handler_object_data =& $decorator;            $this->handler_method_data = 'breakData';        }        if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) {            $decorator =& new XML_HTMLSax_Tab(                $this->handler_object_data,                $this->handler_method_data);            $this->handler_object_data =& $decorator;            $this->handler_method_data = 'breakData';        }        if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) {            $decorator =& new XML_HTMLSax_Entities_Unparsed(                $this->handler_object_data,                $this->handler_method_data);            $this->handler_object_data =& $decorator;            $this->handler_method_data = 'breakData';        }        if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) {            $decorator =& new XML_HTMLSax_Entities_Parsed(                $this->handler_object_data,                $this->handler_method_data);            $this->handler_object_data =& $decorator;            $this->handler_method_data = 'breakData';        }        $this->rawtext = $data;        $this->length = strlen($data);        $this->position = 0;        $this->_parse();    }    /**    * Performs the parsing itself, delegating calls to a specific parser    * state    * @param constant state object to parse with    * @access protected    * @return void    */    function _parse($state = XML_HTMLSAX_STATE_START) {        do {            $state = $this->State[$state]->parse($this);        } while ($state != XML_HTMLSAX_STATE_STOP &&                    $this->position < $this->length);    }}/*** Parser for PHP Versions below 4.3.0. Uses a slower parsing mechanism than* the equivalent PHP 4.3.0+  subclass of StateParser* @package XML_HTMLSax* @access protected* @see XML_HTMLSax_StateParser_Gtet430*/class XML_HTMLSax_StateParser_Lt430 extends XML_HTMLSax_StateParser {    /**    * Constructs XML_HTMLSax_StateParser_Lt430 defining available    * parser options    * @var XML_HTMLSax instance of user front end class    * @access protected    */    function XML_HTMLSax_StateParser_Lt430(& $htmlsax) {        parent::XML_HTMLSax_StateParser($htmlsax);        $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0;        $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0;        $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0;        $this->parser_options['XML_OPTION_TAB_BREAK'] = 0;        $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0;        $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0;        $this->parser_options['XML_OPTION_FULL_ESCAPES'] = 0;    }    /**    * Returns a string from the current position until the first instance of    * one of the characters in the supplied string argument    * @param string string to search until

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -