note 70271 added to function.xml-parser-free
| From: | alex_foe at yahoo dot de | Date: | Mon, 09 Oct 2006 17:07:41 +0000 |
| Subject: | note 70271 added to function.xml-parser-free | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118320@lists.php.net to get a copy of this message | ||
whitout throwing exceptions you could try these for clear parser shutdown:
xml_parse($this->p, null, 1);
full example-class (php4 compatible):
class XML_Parser
{
var $file = null;
var $p = null; #the resource xml-parser
var $__parsing = false;
function XML_Parser($file = null)
{
if (!empty($file)) { $this->file = $file; }
$this->p = xml_parser_create();
xml_set_element_handler($this->p, array(&$this, "element_start"));
register_shutdown_function(array(&$this, "destructor"));
}
function element_start($parser, $name, $attrs) { die("here I die while parsing"); }
function parse_file($file = null)
{
$this->__parsing = true;
if (!empty($file)) { $this->file = $file; }
if (!file_exists($this->file)) { die("file does not exists: $this->file");
return; }
if (!($fp = fopen($this->file, "r"))) { die("could not open XML
input"); }
while ($data = fread($fp, 4096))
{
if (!xml_parse($this->p, $data, feof($fp)))
{
die(
xml_error_string(xml_get_error_code($this->p)
. xml_getcurrent_line_number($this->p)));
}
}
$this->__parsing = false;
}
function destructor()
{
if ($this->__parsing) { xml_parse($this->p, null, 1); }
xml_parser_free($this->p);
}
}
#run_me
$o =& new XML_Parser "some_xml_file.xml";
$o->parse_file();
----
Server IP: 217.160.72.57
Probable Submitter: 212.126.207.114 (proxied: 1.1 GATEWAY)
----
Manual Page -- http://www.php.net/manual/en/function.xml-parser-free.php
Edit -- https://master.php.net/note/edit/70271
Del: integrated -- https://master.php.net/note/delete/70271/integrated
Del: useless -- https://master.php.net/note/delete/70271/useless
Del: bad code -- https://master.php.net/note/delete/70271/bad+code
Del: spam -- https://master.php.net/note/delete/70271/spam
Del: non-english -- https://master.php.net/note/delete/70271/non-english
Del: in docs -- https://master.php.net/note/delete/70271/in+docs
Del: other reasons-- https://master.php.net/note/delete/70271
Reject -- https://master.php.net/note/reject/70271
Search -- https://master.php.net/manage/user-notes.php