DB_Sqlite_Tools
[ class tree: DB_Sqlite_Tools ] [ index: DB_Sqlite_Tools ] [ all elements ]

Source for file XMLParser.php

Documentation is available at XMLParser.php

  1. <?php
  2.  
  3.  
  4. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4  */
  5. // +----------------------------------------------------------------------+
  6. // | PHP version 5                                                        |
  7. // +----------------------------------------------------------------------+
  8. // | Copyright (c) 1997-2004 The PHP Group                                |
  9. // +----------------------------------------------------------------------+
  10. // | This source file is subject to version 3.0 of the PHP license,       |
  11. // | that is bundled with this package in the file LICENSE, and is        |
  12. // | available through the world-wide-web at the following url:           |
  13. // | http://www.php.net/license/3_0.txt.                                  |
  14. // | If you did not receive a copy of the PHP license and are unable to   |
  15. // | obtain it through the world-wide-web, please send a note to          |
  16. // | license@php.net so we can mail you a copy immediately.               |
  17. // +----------------------------------------------------------------------+
  18. // | Authors: David Costa     <gurugeek@php.net>                          |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // \$Id: XMLParser.php,v 1.1 2004/08/19 18:28:15 gurugeek Exp $  $
  22.  
  23.  
  24. // more comments will be added soon. Alpha version of the XML parser
  25. // to be possibly replaced by a proper parse or extension as suggested by
  26. // Stephan Schimdt 
  27.  
  28. class DB_Sqlite_Tools_XMLParser {
  29.         public $fh;
  30.         public $element;
  31.         public $enclosed;
  32.         public $ignoreList = array();
  33.         private $str;
  34.         
  35.         public function __construct($fh$pos = 0{
  36.             $this->fh $fh;
  37.             fseek($fh$pos);
  38.             $this->strlen strlen($this->str);
  39.         }
  40.         public function getNextElement(
  41.         {
  42.             // the loop is so that if we are told to ignore a certain
  43.             // element, then we can continue on to the next one and
  44.             // return that.
  45.             while (true{
  46.                 // obviously, if we're at EOF, then there are no more
  47.                 // elements ;)
  48.                 if (feof($this->fh)) return false;
  49.                 // read up to the first open bracket, storing what's
  50.                 // in between
  51.                 $this->enclosed "";
  52.                 $c fgetc($this->fh);
  53.                 while (($c != '<'&& !feof($this->fh)) {
  54.                     $this->enclosed.= $c;
  55.                     $c fgetc($this->fh);
  56.                 }
  57.                 // read up to the first close bracket that isn't within
  58.                 // quote marks, storing what's in between.
  59.                 $this->element "";
  60.                 $inQuote = false;
  61.                 $c fgetc($this->fh);
  62.                 while (($c != '>'// end if $c == '>'
  63.                  || ($inQuote// unless this is within a quote,
  64.                  || (feof($this->fh)) // or if we have reached EOF.
  65.                 {
  66.                     // toggle quote flag
  67.                     if ($c == '"'$inQuote !$inQuote;
  68.                     $this->element.= $c;
  69.                     $c fgetc($this->fh);
  70.                 }
  71.                 // default action is to accept this element, however we have
  72.                 // to check it against the list of elements to ignore, like
  73.                 // <!-- -->
  74.                 $break = true;
  75.                 foreach($this->ignoreList as $ignore{
  76.                     if (preg_match("/$ignore/"$this->getElement())) $break = false;
  77.                 }
  78.                 // break the while loop if this is an acceptable element
  79.                 if ($breakbreak;
  80.             }
  81.             return true;
  82.         }
  83.         public function ignore($str
  84.         {
  85.             // add $str to ignore list
  86.             $this->ignoreList[$str;
  87.         }
  88.         public function getElement(
  89.         {
  90.             return trim($this->element);
  91.         }
  92.         public function getEnclosed(
  93.         {
  94.             return $this->enclosed;
  95.         }
  96.         public function getElementAttribute($name
  97.         {  
  98.             $el $this->getElement();
  99.             preg_match('/[ ]+'.$name.'[ ]*=[ ]*"([^"]*)"/'$el$result);
  100.             return $result[1];
  101.         }
  102.         public function getElementName(
  103.         {
  104.             preg_match("/^([^ ]*).*$/"$this->getElement()$result);
  105.             #echo $result[1] ;
  106.             return $result[1];
  107.         }
  108.     }
  109. ?>

Documentation generated on Mon, 11 Mar 2019 13:55:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.