mirror of
https://github.com/php/php-src.git
synced 2025-08-21 01:45:16 +02:00
54 lines
No EOL
1.2 KiB
PHP
54 lines
No EOL
1.2 KiB
PHP
<?php
|
|
class xml_stream_parser {
|
|
var $parser;
|
|
|
|
function __construct($stream)
|
|
{
|
|
if (!is_resource($stream)) die("not a stream");
|
|
if (get_resource_type($stream) != "stream") die("not a stream");
|
|
|
|
$this->parser = xml_parser_create();
|
|
|
|
xml_set_object($this->parser, $this);
|
|
xml_set_element_handler($this->parser, "tag_open", "tag_close");
|
|
xml_set_character_data_handler($this->parser, "cdata");
|
|
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
while (!feof($stream)) {
|
|
xml_parse($this->parser, fgets($stream), feof($stream));
|
|
}
|
|
xml_parser_free($this->parser);
|
|
}
|
|
|
|
function tag_open($parser, $tag, $attributes)
|
|
{
|
|
var_dump($parser, $tag, $attributes);
|
|
}
|
|
|
|
function cdata($parser, $cdata)
|
|
{
|
|
var_dump($parser, $cdata);
|
|
}
|
|
|
|
function tag_close($parser, $tag)
|
|
{
|
|
var_dump($parser, $tag);
|
|
}
|
|
|
|
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
|
|
?>
|