Malcerous Posted April 7, 2006 Share Posted April 7, 2006 I am using the Turorial off of PHP Freaks [a href=\"http://www.phpfreaks.com/tutorial_cat/28/PHP-XML.php\" target=\"_blank\"]PHPFreaks Tutorial[/a][code]<?PHPfunction print_error() { global $parser; die(sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser) ));} //create xml parser object$parser = xml_parser_create();//this option ensures that unneccessary white spaces//between successive elements would be removedxml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);//to use XML code correctly we have to turn case folding//(uppercasing) off. XML is case sensitive and upper //casing is in reality XML standards violationxml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);//read XML file into $data$data = implode("",file('http://sports.yahoo.com/nhl/rss.xml'));//parse XML input $data into two arrays://$i_ar - pointers to the locations of appropriate values in//$d_ar - data value arrayxml_parse_into_struct($parser,$data,&$d_ar,&$i_ar) or print_error();//to view content of $d_ar and/or $i_ar uncomment lines below//echo '<pre>';//print_r($d_ar);//print_r($i_ar);//cycle all <item> tags. //$i_ar['item'] contains all pointers to <item> tagsfor($i=0; $i<count($i_ar['item']); $i++) { //since we have <item> nested inside another <item> tag, //we have to check if pointer is to open type tag. if($d_ar[$i_ar['item'][$i]]['type']=='open') { //now for all content within single <item> element //extract needed information for($j=$i_ar['item'][$i]; $j<$i_ar['item'][$i+1]; $j++) { if($d_ar[$j]['tag'] == 'caption') { $caption = $d_ar[$j]['value']; }elseif($d_ar[$j]['tag'] == 'url') { $url = $d_ar[$j]['attributes']['value']; } } //output link echo '<a href="'.$url.'">'.str_repeat('=',$d_ar[$j]['level']-1).$caption.'</a><br>'; }}//unseting XML parser objectxml_parser_free($parser);/**tab-width=4 *indent=4*width=90*/?> [/code]I saved the file as rss.php and goto the page and get the following error.XML Error: syntax error at line 1Does anyone have any ideas why I am getting this meaage?Can you please test this script on your site to see it it works?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.