Forum Moderators: coopster

Message Too Old, No Replies

xml_parse(): Unable to call handler

Anyone using PHP's SAX parser?

         

Stu_Rogers

10:05 am on Aug 26, 2005 (gmt 0)

10+ Year Member



I am attempting to use PHP’s SAX parser to process an XML document, but getting the error:

Warning: xml_parse(): Unable to call handler startElementHandler() in /mnt/drbd/home/mywebsite.com/test.php on line 25

Warning: xml_parse(): Unable to call handler characterDataHandler() in /mnt/drbd/home/mywebsite.com/test.php on line 25

Warning: xml_parse(): Unable to call handler endElementHandler() in /mnt/drbd/home/mywebsite.com/test.php on line 25

These three lines are repeated for each line of my XML.

I am using PHP version 4.4.0 and when I run phpinfo I see:

XML Support active
XML Namespace Support active
EXPAT Version 1.95.6
XSLT support enabled
Backend Sablotron
Sablotron Version 1.0

Any idea why I am getting this error? Am I missing something on my server?

This is my test.php code:

$xml_parser = xml_parser_create();

//set callback functions
xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler($xml_parser, "characterDataHandler");

//read XML file
if (!($fp = fopen("fox.xml", "r"))) {die("File error");}

//parse XML
while ($data = fread($fp, 4096)) {
//error handler
if (!xml_parse($xml_parser, $data, feof($fp))) {
die("XML Parser error: " . xml_error_string(xml_get_error_code($xml_parser)));
}
}

xml_parser_free($xml_parser);

jatar_k

4:55 pm on Aug 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



.... on line 25

which is line 25?

Stu_Rogers

8:54 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Sorry, the error is with the line that calls the xml_parse(). The line looks like this...

if (!xml_parse($xml_parser, $data, feof($fp))) {

As stated though, I suspect its a server config issue - anybody using the XML parser can confirm exactly what I need?

Stu_Rogers

2:39 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



Apologies - I have overlooked defining the event handlers which is why the script wasn't working. I have now added functions for startElementHandler etc and everything is working fine.

jatar_k

4:09 pm on Aug 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nice, glad you got it sorted