cvs: php4 /scripts/ext_skel_ng xml_stream_parser.php
| From: | Hartmut Holzgraefe | Date: | Sat, 26 Apr 2003 15:20:54 +0000 |
| Subject: | cvs: php4 /scripts/ext_skel_ng xml_stream_parser.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20510@lists.php.net to get a copy of this message | ||
hholzgra Sat Apr 26 11:20:54 2003 EDT
Modified files:
/php4/scripts/ext_skel_ng xml_stream_parser.php
Log:
support arrays of error messages in addition to single strings
use PHP 5 style __constructor
Index: php4/scripts/ext_skel_ng/xml_stream_parser.php
diff -u php4/scripts/ext_skel_ng/xml_stream_parser.php:1.2
php4/scripts/ext_skel_ng/xml_stream_parser.php:1.3
--- php4/scripts/ext_skel_ng/xml_stream_parser.php:1.2 Fri Feb 28 01:30:59 2003
+++ php4/scripts/ext_skel_ng/xml_stream_parser.php Sat Apr 26 11:20:18 2003
@@ -2,10 +2,10 @@
class xml_stream_parser {
var $parser;
- function xml_stream_parser($stream)
+ function __construct($stream)
{
- if(!is_resource($stream)) die("not a stream");
- if(get_resource_type($stream) != "stream") die("not a stream");
+ if (!is_resource($stream)) die("not a stream");
+ if (get_resource_type($stream) != "stream") die("not a stream");
$this->parser = xml_parser_create();
@@ -14,7 +14,7 @@
xml_set_character_data_handler($this->parser, "cdata");
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
- while(!feof($stream)) {
+ while (!feof($stream)) {
xml_parse($this->parser, fgets($stream), feof($stream));
}
xml_parser_free($this->parser);
@@ -35,7 +35,19 @@
var_dump($parser, $tag);
}
- function error($msg) {
+ function error($msg)
+ {
+ if (is_array($msg)) {
+ if (count($msg)==1) {
+ $msg = current($msg);
+ } else {
+ foreach ($msg as $text) {
+ echo "$text\n";
+ }
+ $msg = "...";
+ }
+ }
+
die("$msg on line ".xml_get_current_line_number($this->parser));
}
} // end of class xml