0

Hi,
I am using a PHP parser to extract some contents from a RSS feed.
The parser used to work just fine, but when I changed my hosting the parser stopped working and now it shows the following error:

XML Error: not well-formed (invalid token) at line 11

The XML file its a valid RSS feed according to feedvalidator.org and I just can't find the reason why it used to work and now it doesn't. Does anybody know why it is not working in this new hosting?? or if a possible reason for this?

RSS feed:http://www.banxico.org.mx/rsscb/rss?BMXC_canal=fix&BMXC_idioma=es

Thanks!

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by julio gomez
0

It appears that it is not accepting the special characters. Perhaps because the document is ISO8859. Try converting it to UTF8.

0

It appears that it is not accepting the special characters. Perhaps because the document is ISO8859. Try converting it to UTF8.

Thanks for the suggestion, the problem is that I kind of new with php and the parser I have was made by someone else and I'm not sure how to do that, here is the code for the parser including the utf-8:

class RSSParser {

   var $insideitem = false;
   var $tag = "";
   var $valor = "";
	//Function to use at the start of an element
   function start($parser, $tagName, $attrs) {
	   if ($this->insideitem) {
		   $this->tag = $tagName;
	   } elseif ($tagName == "CB:EXCHANGERATE") {
		   $this->insideitem = true;
	   }
   }

	//Function to use at the end of an element
   function stop($parser, $tagName) {
	   if ($tagName == "CB:EXCHANGERATE") {
		   $this->insideitem = false;
	   }
   }
	
	//Function to use when finding character data
   function char($parser, $data) {
	   if ($this->insideitem) {
		   switch ($this->tag) {
			   case "CB:VALUE":
			   $this->valor .= $data;
			   break;
		   }
	   }
   }
} 
	//Initialize the XML parser
$xml_parser=xml_parser_create(); 
$rss_parser = new RSSParser(); 
xml_set_object($xml_parser,&$rss_parser);
	
	//Setting UTF-8
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); 

	//Specify element handler
xml_set_element_handler($xml_parser,"start","stop");

	//Specify data handler
xml_set_character_data_handler($xml_parser,"char");

	//Open XML file
$fp=fopen("http://www.banxico.org.mx/rsscb/rss?BMXC_canal=fix&BMXC_idioma=es","r");

	//Read data
while ($data=fread($fp,4096))
  {
  xml_parse($xml_parser,$data,feof($fp)) or
  die (sprintf("XML Error: %s at line %d",
  xml_error_string(xml_get_error_code($xml_parser)),
  xml_get_current_line_number($xml_parser)));
  }

	//Free the XML parser
xml_parser_free($xml_parser);

I am using the xml_parser_set_option() to change to utf-8 but I am not sure if that is correct.

Any help would be appreciated, thanks

0

I am facing the same problem I was searching and landed here but it's unfortunate that no one has helped with the issue :(

0

Thanks for the help, I tried that before but it didn't work and I don't know if I am doing it correctly.
I am not downloading the whole XML, just a single line.
Considering this how do you suggest using the utf8_encode function in my code??

Thanks!!

0

Something like this perhaps.

xml_parse($xml_parser,utf8_encode($data),feof($fp)) or ..

VERY simple solution.
I tried using utf8_encode($data) before that line and it didn't work. Putting it as you suggest does the trick! thanks!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.