Solved

Error: myRSSParser: Error Reserved XML Name at line 2

Posted on 2009-04-13
9
992 Views
Last Modified: 2012-05-06
Hello, I using a php scritp to parse xml and show links from anothe forum but all of a sudden the code start throwing the following error:

myRSSParser: Error Reserved XML Name at line 2

You can see it here:

http://www.coloradocutthroat.com/testC3/index.php

Now it was working fine today but something was going on with the forums and then this happen. Don't know how to investigate this since no code changes have been made from my page
Here is the code and class for the php:
 
<?PHP 
	
  # Original PHP code by Chirp Internet: www.chirp.com.au
  # Please acknowledge use of this code by including this header.
 
  class myRSSParser
  {
    # keeps track of current and preceding elements
    var $tags = array();
 
    # array containing all feed data
    var $output = array();
 
    # return value for display functions
    var $retval = "";
 
    # constructor for new object
    function myRSSParser($file)
    {
      # instantiate xml-parser and assign event handlers
      $xml_parser = xml_parser_create("");
      xml_set_object($xml_parser, $this);
      xml_set_element_handler($xml_parser, "startElement", "endElement");
      xml_set_character_data_handler($xml_parser, "parseData");
 
      # open file for reading and send data to xml-parser
      $fp = @fopen($file, "r") or die("myRSSParser: Could not open $file for input");
      while($data = fread($fp, 4096)) {
        xml_parse($xml_parser, $data, feof($fp)) or die(
          sprintf("myRSSParser: Error <b>%s</b> at line <b>%d</b><br>",
          xml_error_string(xml_get_error_code($xml_parser)),
          xml_get_current_line_number($xml_parser))
        );
      }
      fclose($fp);
 
      # dismiss xml parser
      xml_parser_free($xml_parser);
    }
 
    function startElement($parser, $tagname, $attrs=array())
    {
      # RSS 2.0 - ENCLOSURE
      if($tagname == "ENCLOSURE" && $attrs) {
        $this->startElement($parser, "ENCLOSURE");
        foreach($attrs as $attr => $attrval) {
          $this->startElement($parser, $attr);
          $this->parseData($parser, $attrval);
          $this->endElement($parser, $attr);
        }
        $this->endElement($parser, "ENCLOSURE");
      }
 
      # check if this element can contain others - list may be edited
      if(preg_match("/^(RDF|RSS|CHANNEL|IMAGE|ITEM)/", $tagname)) {
        if($this->tags) {
          $depth = count($this->tags);
          list($parent, $num) = each($tmp = end($this->tags));
          if($parent) $this->tags[$depth-1][$parent][$tagname]++;
        }
        array_push($this->tags, array($tagname => array()));
      } else {
        if(!preg_match("/^(A|B|I)$/", $tagname)) {
          # add tag to tags array
          array_push($this->tags, $tagname);
        }
      }
    }
 
    function endElement($parser, $tagname)
    {
      if(!preg_match("/^(A|B|I)$/", $tagname)) {
        # remove tag from tags array
        array_pop($this->tags);
      }
    }
 
    function parseData($parser, $data)
    {
      # return if data contains no text
      if(!trim($data)) return;
      $evalcode = "\$this->output";
      foreach($this->tags as $tag) {
        if(is_array($tag)) {
          list($tagname, $indexes) = each($tag);
          $evalcode .= "[\"$tagname\"]";
          if(${$tagname}) $evalcode .= "[" . (${$tagname} - 1) . "]";
          if($indexes) extract($indexes);
        } else {
          if(preg_match("/^([A-Z]+):([A-Z]+)$/", $tag, $matches)) {
            $evalcode .= "[\"$matches[1]\"][\"$matches[2]\"]";
          } else {
            $evalcode .= "[\"$tag\"]";
          }
        }
      }
      eval("$evalcode = $evalcode . '" . addslashes($data) . "';");
    }
 
    # display a single channel as HTML
    function display_channel($data, $limit)
    {
      extract($data);
      if($IMAGE) {
        # display channel image(s)
        foreach($IMAGE as $image) $this->display_image($image);
      }
      if($TITLE) {
        # display channel information
        $this->retval .= "<h1>";
        if($LINK) $this->retval .= "<a href=\"$LINK\" target=\"_blank\">";
        $this->retval .= stripslashes($TITLE);
        if($LINK) $this->retval .= "</a>";
        $this->retval .= "</h1>\n";
        if($DESCRIPTION) $this->retval .= "<p>$DESCRIPTION</p>\n\n";
        $tmp = array();
        if($PUBDATE) $tmp[] = "<small>Published: $PUBDATE</small>";
        if($COPYRIGHT) $tmp[] = "<small>Copyright: $COPYRIGHT</small>";
        if($tmp) $this->retval .= "<p>" . implode("<br>\n", $tmp) . "</p>\n\n";
        $this->retval .= "<div class=\"divider\"><!-- --></div>\n\n";
      }
      if($ITEM) {
        # display channel item(s)
        foreach($ITEM as $item) {
          $this->display_item($item, "CHANNEL");
          if(is_int($limit) && --$limit <= 0) break;
        }
      }
    }
 
    # display a single image as HTML
    function display_image($data, $parent="")
    {
      extract($data);
      if(!$URL) return;
 
      $this->retval .= "<p>";
      if($LINK) $this->retval .= "<a href=\"$LINK\" target=\"_blank\">";
      $this->retval .= "<img src=\"$URL\"";
      if($WIDTH && $HEIGHT) $this->retval .= " width=\"$WIDTH\" height=\"$HEIGHT\"";
      $this->retval .= " border=\"0\" alt=\"$TITLE\">";
      if($LINK) $this->retval .= "</a>";
      $this->retval .= "</p>\n\n";
    }
 
    # display a single item as HTML
    function display_item($data, $parent)
    {
      extract($data);
      if(!$TITLE) return;
 
      $this->retval .=  "<p><b>";
      if($LINK) $this->retval .=  "<a href=\"$LINK\" target=\"_blank\">";
      $this->retval .= stripslashes($TITLE);
      if($LINK) $this->retval .= "</a>";
      $this->retval .=  "</b>";
      if(!$PUBDATE && $DC["DATE"]) $PUBDATE = $DC["DATE"];
      if($PUBDATE) $this->retval .= " <small>($PUBDATE)</small>";
      $this->retval .=  "</p>\n";
 
      # use feed-formatted HTML if provided
      if($CONTENT["ENCODED"]) {
        $this->retval .= "<p>" . stripslashes($CONTENT["ENCODED"]) . "</p>\n";
      } elseif($DESCRIPTION) {
        $this->retval .=  "<p>" . stripslashes($DESCRIPTION) . "</p>\n\n";
      }
 
      # RSS 2.0 - ENCLOSURE
      if($ENCLOSURE) {
        $this->retval .= "<p><small><b>Media:</b> <a href=\"{$ENCLOSURE['URL']}\">";
        $this->retval .= $ENCLOSURE['TYPE'];
        $this->retval .= "</a> ({$ENCLOSURE['LENGTH']} bytes)</small></p>\n\n";
      }
 
      if($COMMENTS) {
        $this->retval .= "<p style=\"text-align: right;\"><small>";
        $this->retval .= "<a href=\"$COMMENTS\">Comments</a>";
        $this->retval .= "</small></p>\n\n";
      }
    }
 
    function fixEncoding($input, $output_encoding)
    {
      $encoding = mb_detect_encoding($input);
      switch($encoding) {
        case 'ASCII':
        case $output_encoding:
          return $input;
        case '':
          return mb_convert_encoding($input, $output_encoding);
        default:
          return mb_convert_encoding($input, $output_encoding, $encoding);
      }
    }
 
    # display entire feed as HTML
    function getOutput($limit=false, $output_encoding='UTF-8')
    {
      $this->retval = "";
      $start_tag = key($this->output);
 
      switch($start_tag) {
        case "RSS":
          # new format - channel contains all
          foreach($this->output[$start_tag]["CHANNEL"] as $channel) {
            $this->display_channel($channel, $limit);
          }
          break;
 
        case "RDF:RDF":
          # old format - channel and items are separate
          foreach($this->output[$start_tag]["CHANNEL"] as $channel) {
            $this->display_channel($channel, $limit);
          }
          foreach($this->output[$start_tag]["ITEM"] as $item) {
            $this->display_item($item, $start_tag);
          }
          break;
 
        case "HTML":
          die("Error: cannot parse HTML document as RSS");
 
        default:
          die("Error: unrecognized start tag '$start_tag' in getOutput()");
      }
 
      return $this->fixEncoding($this->retval, $output_encoding);
    }
 
    # return raw data as array
    function getRawOutput($output_encoding='UTF-8')
    {
      return $this->fixEncoding($this->output, $output_encoding);
    }
  }
?>

Open in new window

0
Comment
Question by:DancingFighterG
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:twocandles
ID: 24135712
Probably one of the lines you're parsing contains a reserved name...can you check that?
0
 

Author Comment

by:DancingFighterG
ID: 24137653
What do you mean a revsersed name?
0
 
LVL 6

Expert Comment

by:twocandles
ID: 24137853
Are you sure the xml you're parsing is syntactically well formed? could you print out the xml before parsing?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:DancingFighterG
ID: 24138495
Right now I cleaned the current rss threads and I am still getting that error so right now I don't what it is acutally parsing.
0
 

Author Comment

by:DancingFighterG
ID: 24138520
The weird thing is that it's happen on every page that I use rss feeds to populate my site. I don't know how to troubleshoot this at all?
0
 
LVL 6

Accepted Solution

by:
twocandles earned 500 total points
ID: 24138747
Have you tested with an empty file to see whether it works or not? It seems a problem with the xml formatting.... maybe your class doesn't handle an empy file.

Could you post the starting lines of the file you're parsing?
0
 
LVL 6

Expert Comment

by:twocandles
ID: 24138767
Another possible issue: the whole parsing code is yours? or you're including external code?
0
 

Author Comment

by:DancingFighterG
ID: 24138777
I actually just did that. I took out the rss link out of the code that displays the data and it gave me the correct error so it's something going on with the rss export feed coming from my forums. It's definitly now the code. I'm looking into the feeds right now.
0
 

Author Comment

by:DancingFighterG
ID: 24140036
Ok, it's something definitly going with the export rss feeds for my forum. It's not my code because I just tested it and other xml links work just fine with my code. At this point this is something for invisions boards to fix. Thanks guys!!
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
echo paypal data on screen 5 52
PHP Parse error: syntax error, unexpected '[' 1 25
I wonder how people fake their ip address? 3 39
Showing random records from database 10 37
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question