Now that we have created the required functions, let's continue with the meat of the code: function parsefile($RSSfile){ // Create an xml parser $xmlParser = xml_parser_create(); // Set up element handler xml_set_element_handler( $xmlParser, "startTag", "endTag" );
// Set up character handler xml_set_character_data_handler( $xmlParser, "TxtTag" ); // Open connection to RSS XML file for parsing. $fp = fopen( $RSSfile,"r" ) or die( "Cannot read RSS data file." );
// Parse XML data from RSS file. while( $data = fread( $fp, 4096 ) ) { xml_parse( $xmlParser, $data, feof( $fp ) );
}
// Close file open handler fclose( $fp ); // Free xml parser from memory xml_parser_free( $xmlParser ); } The above function calls both the startTag/endTag functions to loop through the XML file and displays the contents.
blog comments powered by Disqus |
|
|
|
|
|
|
|