cvs: pear /DB_Sqlite_Tools/Tools XMLParser.php
| From: | David Costa | Date: | Sun, 05 Sep 2004 16:40:55 +0000 |
| Subject: | cvs: pear /DB_Sqlite_Tools/Tools XMLParser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-23665@lists.php.net to get a copy of this message | ||
gurugeek Sun Sep 5 12:40:55 2004 EDT
Modified files:
/pear/DB_Sqlite_Tools/Tools XMLParser.php
Log:
Fixed indenting, CS.
http://cvs.php.net/diff.php/pear/DB_Sqlite_Tools/Tools/XMLParser.php?r1=1.1&r2=1.2&ty=u
Index: pear/DB_Sqlite_Tools/Tools/XMLParser.php
diff -u pear/DB_Sqlite_Tools/Tools/XMLParser.php:1.1 pear/DB_Sqlite_Tools/Tools/XMLParser.php:1.2
--- pear/DB_Sqlite_Tools/Tools/XMLParser.php:1.1 Thu Aug 19 14:28:15 2004
+++ pear/DB_Sqlite_Tools/Tools/XMLParser.php Sun Sep 5 12:40:55 2004
@@ -18,7 +18,7 @@
// | Authors: David Costa <gurugeek@php.net> |
// +----------------------------------------------------------------------+
//
-// \$Id: XMLParser.php,v 1.1 2004/08/19 18:28:15 gurugeek Exp $ $
+// \$Id: XMLParser.php,v 1.2 2004/09/05 16:40:55 gurugeek Exp $ $
// more comments will be added soon. Alpha version of the XML parser
@@ -26,112 +26,77 @@
// Stephan Schimdt
class DB_Sqlite_Tools_XMLParser {
- public $fh;
- public $element;
- public $enclosed;
- public $ignoreList = array();
-
- public function __construct( $fh, $pos = 0 )
- {
- $this->fh = $fh ;
- fseek( $fh, $pos ) ;
- $this->strlen = strlen( $this->str ) ;
- }
-
- public function getNextElement()
- {
- // the loop is so that if we are told to ignore a certain
- // element, then we can continue on to the next one and
- // return that.
- while(true) {
-
- // obviously, if we're at EOF, then there are no more
- // elements ;)
- if( feof($this->fh) ) return false ;
-
- // read up to the first open bracket, storing what's
- // in between
-
- $this->enclosed = "" ;
- $c = fgetc( $this->fh ) ;
-
- while( ($c != '<') && !feof($this->fh) )
- {
- $this->enclosed .= $c ;
- $c = fgetc( $this->fh ) ;
- }
-
- // read up to the first close bracket that isn't within
- // quote marks, storing what's in between.
-
- $this->element = "" ;
- $inQuote = false ;
- $c = fgetc($this->fh) ;
-
- while(
- ($c != '>') // end if $c == '>'
- || ($inQuote) // unless this is within a quote,
- || (feof($this->fh)) // or if we have reached EOF.
- ) {
-
- // toggle quote flag
- if( $c == '"' ) $inQuote = !$inQuote ;
-
- $this->element .= $c ;
- $c = fgetc($this->fh) ;
- }
-
- // default action is to accept this element, however we have
- // to check it against the list of elements to ignore, like
- // <!-- -->
-
- $break = true ;
-
- foreach( $this->ignoreList as $ignore ) {
- if( preg_match("/$ignore/", $this->getElement()) )
- $break = false ;
- }
-
- // break the while loop if this is an acceptable element
-
- if( $break ) break ;
-
- }
- return true ;
- }
-
- public function ignore( $str )
- {
- // add $str to ignore list
-
- $this->ignoreList[] = $str ;
- }
-
- public function getElement()
- {
- return trim( $this->element ) ;
- }
-
- public function getEnclosed()
- {
- return $this->enclosed ;
- }
-
- public function getElementAttribute( $name )
- {
- $el = $this->getElement() ;
-
- preg_match( '/[ ]+'.$name.'[ ]*=[ ]*"([^"]*)"/', $el,
$result ) ;
- return $result[1] ;
-
- }
-
- public function getElementName()
- {
- preg_match( "/^([^ ]*).*$/", $this->getElement(), $result ) ;
- #echo $result[1] ;
- return $result[1] ;
- }
-}
-
+ public $fh;
+ public $element;
+ public $enclosed;
+ public $ignoreList = array();
+ public function __construct($fh, $pos = 0) {
+ $this->fh = $fh;
+ fseek($fh, $pos);
+ $this->strlen = strlen($this->str);
+ }
+ public function getNextElement() {
+ // the loop is so that if we are told to ignore a certain
+ // element, then we can continue on to the next one and
+ // return that.
+ while (true) {
+ // obviously, if we're at EOF, then there are no more
+ // elements ;)
+ if (feof($this->fh)) return false;
+ // read up to the first open bracket, storing what's
+ // in between
+ $this->enclosed = "";
+ $c = fgetc($this->fh);
+ while (($c != '<') && !feof($this->fh)) {
+ $this->enclosed.= $c;
+ $c = fgetc($this->fh);
+ }
+ // read up to the first close bracket that isn't within
+ // quote marks, storing what's in between.
+ $this->element = "";
+ $inQuote = false;
+ $c = fgetc($this->fh);
+ while (($c != '>') // end if $c == '>'
+ || ($inQuote) // unless this is within a quote,
+ || (feof($this->fh)) // or if we have reached EOF.
+ ) {
+ // toggle quote flag
+ if ($c == '"') $inQuote = !$inQuote;
+ $this->element.= $c;
+ $c = fgetc($this->fh);
+ }
+ // default action is to accept this element, however we have
+ // to check it against the list of elements to ignore, like
+ // <!-- -->
+ $break = true;
+ foreach($this->ignoreList as $ignore) {
+ if (preg_match("/$ignore/", $this->getElement())) $break = false;
+ }
+ // break the while loop if this is an acceptable element
+ if ($break) break;
+ }
+ return true;
+ }
+ public function ignore($str) {
+ // add $str to ignore list
+ $this->ignoreList[] = $str;
+ }
+ public function getElement() {
+ return trim($this->element);
+ }
+ public function getEnclosed() {
+ return $this->enclosed;
+ }
+ public function getElementAttribute($name) {
+ $el = $this->getElement();
+ preg_match('/[ ]+'.$name.'[ ]*=[ ]*"([^"]*)"/', $el,
$result);
+ return $result[1];
+ }
+ public function getElementName() {
+ preg_match("/^([^ ]*).*$/", $this->getElement(), $result);
+ #echo $result[1] ;
+ return $result[1];
+ }
+ }
?>
+