b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_ext/phpsvnclient/xml2Array.php - 59 lines - 1844 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /* Taken from http://www.php.net/manual/en/function.xml-parse.php#52567
   4    Modified by Martin Guppy <http://www.deadpan110.com/>
   5    Usage
   6    Grab some XML data, either from a file, URL, etc. however you want.
   7    Assume storage in $strYourXML;
   8  
   9    $arrOutput = new xml2Array($strYourXML);
  10    print_r($arrOutput); //print it out, or do whatever!
  11   */
  12  if( ! defined( 'EVO_MAIN_INIT' ) ) die( 'Please, do not access this page directly.' );
  13  
  14  class xml2Array {
  15  
  16      private $arrOutput = array();
  17      private $resParser;
  18      private $strXmlData;
  19  
  20      public function xmlParse($strInputXML) {
  21      $this->resParser = xml_parser_create();
  22      xml_set_object($this->resParser, $this);
  23      xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
  24      xml_set_character_data_handler($this->resParser, "tagData");
  25  
  26      $this->strXmlData = xml_parse($this->resParser, $strInputXML);
  27      if (!$this->strXmlData) {
  28          die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->resParser)), xml_get_current_line_number($this->resParser)));
  29      }
  30  
  31      xml_parser_free($this->resParser);
  32      // Changed by Deadpan110
  33      //return $this->arrOutput;
  34      return $this->arrOutput[0];
  35      }
  36  
  37      private function tagOpen($parser, $name, $attrs) {
  38      $tag = array("name" => $name, "attrs" => $attrs);
  39      array_push($this->arrOutput, $tag);
  40      }
  41  
  42      private function tagData($parser, $tagData) {
  43      if (trim($tagData)) {
  44          if (isset($this->arrOutput[count($this->arrOutput) - 1]['tagData'])) {
  45          $this->arrOutput[count($this->arrOutput) - 1]['tagData'] .= $tagData;
  46          } else {
  47          $this->arrOutput[count($this->arrOutput) - 1]['tagData'] = $tagData;
  48          }
  49      }
  50      }
  51  
  52      private function tagClosed($parser, $name) {
  53      $this->arrOutput[count($this->arrOutput) - 2]['children'][] = $this->arrOutput[count($this->arrOutput) - 1];
  54      array_pop($this->arrOutput);
  55      }
  56  
  57  }
  58  
  59  ?>

title

Description

title

Description

title

Description

title

title

Body