can somebody please explain to me why in the following code if i uncomment the commented code and comment the lines of code followed by //*****
i get empty page.
thanks...
<?
$the_html = "";
$file = "xmlfile.xml";
$opening_tag = array(
"HOTEL" => "<table width=\"50%\"><tr><td bgcolor=red>",
);
$closing_tag = array(
"NAME" => "<br>"
);
function startElement($parser, $name, $attrs) {
global $opening_tag;
if ($htmltag = $opening_tag[$name]) {
print "$htmltag"; //*****
// $the_html .= $htmltag;
}
}
function endElement($parser, $name) {
global $closing_tag;
if ($name == "HOTEL") {
print "</td></tr></table>"; //***********
// $the_html .= "</td></tr></table>";
}
else
{
// $the_html .="<br>";
print "<br>"; //********
}
}
function characterData($parser, $data) {
print "$data"; //********
// $the_html .= $data;
}
$xml_parser = xml_parser_create();
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)));
}
}
//print "$the_html";
xml_parser_free($xml_parser);
?>