"
", "DATE" => "", "STRONG" => "", "TEXT" => "\n", "LINK" => " "href=\"", "PAGE" => "href=\"", "SUP" => "", ); $endTags = array( "NEWSITEM" => "
", "DATE" => " : ", "STRONG" => "", "TEXT" => "\n", "LINK" => "", "URL" => "\">", "PAGE" => ".php\">", "SUP" => "", ); // These vars track the number of items show, depending on the 'show' var $items = 5; $show = $_GET['show']; if ($show) { if ($show == 'all') { $items = -1; } else { $items = $show; } } // // *** Start of XML control content *** // function startElement($parser, $name, $attrs) { global $startTags; // if tag exists as key, print value if ($startTags[$name]) { echo $startTags[$name]; } } function endElement($parser, $name) { global $endTags, $items, $maxitems; if ($endTags[$name]) { echo $endTags[$name]; } if ($name == 'NEWSITEM') { if ($items != -1) { $items--; } } } // process data between tags function characterData($parser, $data) { echo $data; } // // *** End of XML control content *** // // // *** Code to generate content *** // // Include the header; head($style, 'News', ''); // initialize parser $xml_parser = xml_parser_create(); $file = 'content/news.xml'; // set callback functions xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); // open XML file if (!($fp = fopen($file, "r"))) { die("Cannot locate XML data file: $file"); } // read and parse data while ( ($data = fgets($fp, 4096)) && ($items != 0) ) { // error handler 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))); } } // clean up xml_parser_free($xml_parser); if ($items != -1) { ?>