i'm trying to parse a very simple xml file. every time i get this parse error:
Parse error: parse error in /xmltest01.php on line 84
the thing is line 84 is 10 lines after the closing </html> tag. there is nothing there.
the xml file has a lot a tags but i'm trying with only 2...
some help please... i'll appreciate it...
here is the code:
<html>
<body>
<?
$the_html ="";
$file = "testxml.xml";
$open_tag = array(
"HOTELID" => "<FONT COLOR=#BBBB00>",
"NAME" => "<FONT COLOR=#BBBB00>"
);
$close_tag = array(
"HOTELID" => "</FONT>",
"NAME" => "</FONT>"
);
function startElement($parser, $name, $attrs) {
// global $open_tag;
if ($format= $open_tag[$name]) {
$the_html .= $format;
}
function endElement($parser, $name) {
// global $close_tag;
if ($format= $close_tag[$name]) {
$the_html .= $format;
}
}
function characterData($parser, $data) {
$the_html .= $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");
}
while ($data = fread($fp, 4096)) {
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)));
}
}
xml_parser_free($xml_parser);
?>
</body>
</html>