[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/domit/ -> dom_xmlrpc_parser.php (source)

   1  <?php
   2  /**
   3  * dom_xmlrpc_parser is the base parsing class
   4  * @package dom-xmlrpc
   5  * @copyright (C) 2004 John Heinstein. All rights reserved
   6  * @license http://www.gnu.org/copyleft/lesser.html LGPL License
   7  * @author John Heinstein <johnkarl@nbnet.nb.ca>
   8  * @link http://www.engageinteractive.com/dom_xmlrpc/ DOM XML-RPC Home Page
   9  * DOM XML-RPC is Free Software
  10  **/
  11  
  12  if (!defined('DOM_XMLRPC_INCLUDE_PATH')) {
  13      define('DOM_XMLRPC_INCLUDE_PATH', (dirname(__FILE__) . "/"));
  14  }
  15  
  16  require_once (DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_constants.php');
  17  
  18  /**
  19  * The base parsing class
  20  *
  21  * @package dom-xmlrpc
  22  * @author John Heinstein <johnkarl@nbnet.nb.ca>
  23  */
  24  class dom_xmlrpc_parser {
  25      /** @var object A wrapper for methodCall and methodResponse arrays */
  26      var $arrayDocument = null;
  27      /** @var string A temporary container for parsed string data */
  28      var $charContainer = '';
  29      /** @var array A stack holding an hierarchical list of arraytypes (i.e., 'array' or 'struct' or '__phpobject__') */
  30      var $lastArrayType = array();
  31      /** @var array A stack holding an hierarchical sequence of array references */
  32      var $lastArray = array();
  33      /** @var array A stack holding an hierarchical sequence of struct names */
  34      var $lastStructName = array();
  35  
  36      /**
  37      * Parses the supplied XML text
  38      * @param string The XML text
  39      * @param boolean True if SAXY is to be used
  40      * @return boolean True if the parsing was successful
  41      */
  42  	function parseXML($xmlText, $useSAXY = true) {
  43          $xmlText = trim($xmlText);
  44  
  45          require_once (DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_array_document.php');
  46          $this->arrayDocument = new dom_xmlrpc_array_document();
  47  
  48          if ($xmlText != '') {
  49              if ($useSAXY || (!function_exists('xml_parser_create'))) {
  50                  //use SAXY parser to generate array
  51                  return $this->parseSAXY($xmlText);
  52              }
  53              else {
  54                  //use Expat parser to generate array
  55                  return $this->parse($xmlText);
  56              }
  57          }
  58  
  59          return false;
  60      } //parseXML
  61  
  62      /**
  63      * Invokes Expat to parse the XML text
  64      * @param string The XML text
  65      * @return boolean True if the parsing was successful
  66      */
  67  	function parse($xmlText) {
  68          //create instance of expat parser (should be included in php distro)
  69          $parser = xml_parser_create();
  70  
  71          //set handlers for SAX events
  72          xml_set_object($parser, $this);
  73          xml_set_element_handler($parser, 'startElement', 'endElement');
  74          xml_set_character_data_handler($parser, array(&$this, 'dataElement'));
  75          xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  76          xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  77  
  78          //parse out whitespace -  (XML_OPTION_SKIP_WHITE = 1 does not
  79          //seem to work consistently across versions of PHP and Expat
  80          $xmlText = eregi_replace('>' . "[[:space:]]+" . '<' , '><', $xmlText);
  81  
  82          $success = xml_parse($parser, $xmlText);
  83          xml_parser_free($parser);
  84  
  85          return $success;
  86      } //parse
  87  
  88      /**
  89      * Invokes SAXY to parse the XML text
  90      * @param string The XML text
  91      * @return boolean True if the parsing was successful
  92      */
  93  	function parseSAXY($xmlText) {
  94          //create instance of SAXY parser
  95          require_once (DOM_XMLRPC_INCLUDE_PATH . 'xml_saxy_parser.php');
  96          $parser = new SAXY_Lite_Parser();
  97  
  98          $parser->xml_set_element_handler(array(&$this, 'startElement'), array(&$this, 'endElement'));
  99          $parser->xml_set_character_data_handler(array(&$this, 'dataElement'));
 100  
 101          $success =  $parser->parse($xmlText);
 102  
 103          return $success;
 104      } //parseSAXY
 105  
 106      /**
 107      * Returns a reference to the array document
 108      * @return array A reference to the array document
 109      */
 110      function &getArrayDocument() {
 111          return $this->arrayDocument;
 112      } //getArrayDocument
 113  
 114      /**
 115      * Abstract method for handling start element events
 116      * @param object A reference to the SAX parser
 117      * @param string The name of the start element tag
 118      * @param array An array of attributes (never used by XML-RPC spec)
 119      */
 120  	function startElement($parser, $name, $attrs) {
 121          //must override
 122      } //startElement
 123  
 124      /**
 125      * Abstract method for handling end element events
 126      * @param object A reference to the SAX parser
 127      * @param string The name of the end element tag
 128      */
 129  	function endElement($parser, $name) {
 130          //must override
 131      } //endElement
 132  
 133      /**
 134      * Abstract method for adding an XML-RPC value to the results array
 135      * @param mixed The value
 136      */
 137  	function addValue($value) {
 138          //must override
 139      } //addValue
 140  
 141      /**
 142      * Abstract method for handling character data events
 143      * @param object A reference to the SAX parser
 144      * @param string The character data
 145      */
 146  	function dataElement($parser, $data) {
 147          $this->charContainer .= $data;
 148      } //dataElement
 149  } //dom_xmlrpc_parser
 150  
 151  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics