Solved

Error: myRSSParser: Error Reserved XML Name at line 2

Posted on 2009-04-13
9
994 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 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