Warning: xml_parse(): Unable to call handler characterDataHandler()



I was connecting to the news.google.com rss feed through php. I am just a beginner in php, and I am getting this error



Warning: xml_parse(): Unable to call handler characterDataHandler() in ....(file name)....



This is my code:



function characterDataHandler ( $parser, $element ){
echo " Data Parsed: \"" . htmlspecialchars( $data ) . "\"\n";
}
function parseError ( $parser ) {
$error = xml_error_string( xml_get_error_code( $parser ) );
$errorLine = xml_get_current_line_number( $parser );
$errorColoumn = xml_get_current_column_number( $parser );
return "Catastrophic Failure: $error at $errorLine on $errorColoumn no coloumn";

}
$parser = xml_parser_create();
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false );

xml_set_character_data_handler( $parser, "characterDataHandler" );

$xml = file_get_contents( "http://news.google.com/?output=rss" );
echo htmlspecialchars($xml);
xml_parse($parser, $xml);
xml_parser_free( $parser );


and is also giving this error:



Notice: Undefined variable: data in C:\xampp\htdocs\news\parser.php on line 14 Data Parsed: '' "



If there is some real mistake please give the code which would be correct for that part.


No comments:

Post a Comment