Jump to content


PHP XLM PARSE "XML Error: syntax error at line 1"

  • Please log in to reply
No replies to this topic

#1 Malcerous

  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 07 April 2006 - 04:36 PM

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]

function print_error() {
    global $parser;
    die(sprintf("XML Error: %s at line %d",

//create xml parser object
$parser = xml_parser_create();

//this option ensures that unneccessary white spaces
//between successive elements would be removed

//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 violation

//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 array
xml_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>';

//cycle all <item> tags. 
//$i_ar['item'] contains all pointers to <item> tags
for($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 object


I saved the file as rss.php and goto the page and get the following error.

XML Error: syntax error at line 1

Does anyone have any ideas why I am getting this meaage?
Can you please test this script on your site to see it it works??

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users