cvs: php4 /pear/XML Parser.php
| From: | Thomas V.V.Cox | Date: | Fri, 06 Jul 2001 01:32:06 +0000 |
| Subject: | cvs: php4 /pear/XML Parser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-211@lists.php.net to get a copy of this message | ||
cox Thu Jul 5 21:32:06 2001 EDT
Modified files:
/php4/pear/XML Parser.php
Log:
note about the class needs PHP >= 4.0.4pl1 and removed trailing white spaces
Index: php4/pear/XML/Parser.php
diff -u php4/pear/XML/Parser.php:1.15 php4/pear/XML/Parser.php:1.16
--- php4/pear/XML/Parser.php:1.15 Mon Apr 16 18:17:42 2001
+++ php4/pear/XML/Parser.php Thu Jul 5 21:32:04 2001
@@ -31,6 +31,7 @@
* - a test using all expat handlers
* - options (folding, output charset)
* - different parsing modes
+ * @notes It requires PHP 4.0.4pl1 or greater
*/
class XML_Parser extends PEAR {
// {{{ properties
@@ -39,22 +40,22 @@
* @var resource XML parser handle
*/
var $parser;
-
+
/**
* @var resource File handle if parsing from a file
*/
var $fp;
-
+
/**
* @var boolean Whether to do case folding
*/
var $folding = true;
-
+
/**
* @var string Mode of operation, one of "event" or "func"
*/
var $mode;
-
+
/**
* Mapping from expat handler function to class method.
*
@@ -68,7 +69,7 @@
"notation_decl_handler" => "notationHandler",
"external_entity_ref_handler" => "entityrefHandler"
);
-
+
/** @var string source encoding */
var $srcenc;
@@ -92,7 +93,7 @@
function XML_Parser($srcenc = null, $mode = "event", $tgtenc = null)
{
$this->PEAR('XML_Parser_Error');
-
+
if ($srcenc === null) {
$xp = @xml_parser_create();
} else {
@@ -118,22 +119,22 @@
/**
* Sets the mode and all handler.
- *
+ *
* @param string
* @see $handler
*/
function setMode($mode) {
-
+
$this->mode = $mode;
-
+
xml_set_object($this->parser, $this);
-
+
switch ($mode) {
-
+
case "func":
xml_set_element_handler($this->parser, "funcStartHandler",
"funcEndHandler");
break;
-
+
case "event":
xml_set_element_handler($this->parser, "startHandler",
"endHandler");
break;
@@ -142,16 +143,16 @@
foreach ($this->handler as $xml_func => $method)
if (method_exists($this, $method)) {
$xml_func = "xml_set_" . $xml_func;
- $xml_func($this->parser, $method);
+ $xml_func($this->parser, $method);
}
-
+
}
// }}}
// {{{ setInputFile()
/**
- * Defines
+ * Defines
*
* @param string Filename (full path)
* @return resource fopen handle of the given file
@@ -160,13 +161,13 @@
* @access public
*/
function setInputFile($file) {
-
+
$fp = @fopen($file, "rb");
if (is_resource($fp)) {
$this->fp = $fp;
return $fp;
}
-
+
return $this->raiseError($php_errormsg);
}
@@ -175,18 +176,18 @@
/**
* Sets the file handle to use with parse().
- *
+ *
* @param resource fopen
* @access public
* @see parse(), setInputFile()
*/
function setInput($fp) {
-
+
if (is_resource($fp)) {
$this->fp = $fp;
return true;
}
-
+
return $this->raiseError("not a file resource");
}
@@ -195,30 +196,30 @@
/**
* Central parsing function.
- *
+ *
* @throws XML_Parser_Error
* @return boolean true on success
* @see parseString()
* @access public
*/
function parse() {
-
+
if (!is_resource($this->fp)) {
return $this->raiseError("no input");
}
-
+
while ($data = fread($this->fp, 2048)) {
-
+
$err = $this->parseString($data, feof($this->fp));
if (PEAR::isError($err)) {
fclose($this->fp);
return $err;
}
-
+
}
-
+
fclose($this->fp);
-
+
return true;
}
@@ -227,20 +228,20 @@
/**
* Parses a string.
- *
+ *
* @param string XML data
* @param boolean ???
* @throws XML_Parser_Error
* @return mixed true on success or a string with the xml parser error
*/
function parseString($data, $eof = false) {
-
+
if (!xml_parse($this->parser, $data, $eof)) {
$err = $this->raiseError($this->parser);
xml_parser_free($this->parser);
return $err;
}
-
+
return true;
}
@@ -248,11 +249,11 @@
// {{{ funcStartHandler()
function funcStartHandler($xp, $elem, $attribs) {
-
+
if (method_exists($this, $elem)) {
call_user_method($elem, $this, $xp, $elem, &$attribs);
}
-
+
}
// }}}
@@ -265,18 +266,18 @@
call_user_method($func, $this, $xp, $elem);
}
}
-
-
+
+
/**
- *
+ *
* @abstract
*/
function StartHandler($xp, $elem, $attribs)
{
return NULL;
- }
-
-
+ }
+
+
/**
*
* @abstract
@@ -285,8 +286,8 @@
{
return NULL;
}
-
-
+
+
// }}}
}
@@ -307,7 +308,7 @@
xml_get_current_line_number($msgorparser));
}
$this->PEAR_Error($msgorparser, $code, $mode, $level);
-
+
}
// }}}