Hi,
I am having a problem parsing xml with php. I am running on windows 98 with apache
1.3.14. Here is a code snippet:
<?php
$file="data\logs.xml";
function startElement($parser, $name, $attrs) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "<$htmltag>";
}
}
function endElement($parser, $name) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "</$htmltag>";
}
}
function characterData($parser, $data) {
//print $data;
}
$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the tag in $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
print "<pre>";
while ($data = fread($fp, 4096)) {
print $data;
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
print "</pre>";
xml_parser_free($xml_parser);
?>
End of snippet...
When I try to run this, I get an error box saying that apache has performed an illegal
operation and then my computer locks up. If I comment out the set_*_handler
statements, everything runs fine.
Apache will display the xml file just fine if I hit it directly. (If that is of any
value.)
Anyone have any idea what's wrong?
Thanks in advance for your help,
Chad
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]