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.         public function __construct($fh$pos = 0{
  34.             $this->fh $fh;
  35.             fseek($fh$pos);
  36.             $this->strlen strlen($this->str);
  37.         }
  38.         public function getNextElement(
  39.         {
  40.             // the loop is so that if we are told to ignore a certain
  41.             // element, then we can continue on to the next one and
  42.             // return that.
  43.             while (true{
  44.                 // obviously, if we're at EOF, then there are no more
  45.                 // elements ;)
  46.                 if (feof($this->fh)) return false;
  47.                 // read up to the first open bracket, storing what's
  48.                 // in between
  49.                 $this->enclosed "";
  50.                 $c fgetc($this->fh);
  51.                 while (($c != '<'&& !feof($this->fh)) {
  52.                     $this->enclosed.= $c;
  53.                     $c fgetc($this->fh);
  54.                 }
  55.                 // read up to the first close bracket that isn't within
  56.                 // quote marks, storing what's in between.
  57.                 $this->element "";
  58.                 $inQuote = false;
  59.                 $c fgetc($this->fh);
  60.                 while (($c != '>'// end if $c == '>'
  61.                  || ($inQuote// unless this is within a quote,
  62.                  || (feof($this->fh)) // or if we have reached EOF.
  63.                 {
  64.                     // toggle quote flag
  65.                     if ($c == '"'$inQuote !$inQuote;
  66.                     $this->element.= $c;
  67.                     $c fgetc($this->fh);
  68.                 }
  69.                 // default action is to accept this element, however we have
  70.                 // to check it against the list of elements to ignore, like
  71.                 // <!-- -->
  72.                 $break = true;
  73.                 foreach($this->ignoreList as $ignore{
  74.                     if (preg_match("/$ignore/"$this->getElement())) $break = false;
  75.                 }
  76.                 // break the while loop if this is an acceptable element
  77.                 if ($breakbreak;
  78.             }
  79.             return true;
  80.         }
  81.         public function ignore($str
  82.         {
  83.             // add $str to ignore list
  84.             $this->ignoreList[$str;
  85.         }
  86.         public function getElement(
  87.         {
  88.             return trim($this->element);
  89.         }
  90.         public function getEnclosed(
  91.         {
  92.             return $this->enclosed;
  93.         }
  94.         public function getElementAttribute($name
  95.         {  
  96.             $el $this->getElement();
  97.             preg_match('/[ ]+'.$name.'[ ]*=[ ]*"([^"]*)"/'$el$result);
  98.             return $result[1];
  99.         }
  100.         public function getElementName(
  101.         {
  102.             preg_match("/^([^ ]*).*$/"$this->getElement()$result);
  103.             #echo $result[1] ;
  104.             return $result[1];
  105.         }
  106.     }
  107. ?>

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