Connecting Tech Pros Worldwide Help | Site Map

simplexml_load_file problem

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: 4 Weeks Ago
Hi,

I have a problem parsing an rss feed using simplexml_load_file - this is strange as i have used the same code to parse literally 1000s of different rss feeds in the past, and even stranger in that if i put the feed source on our server as a .xml file then my code parses it successfully.

The relevant code snippet:
Expand|Select|Wrap|Line Numbers
  1. $xml = simplexml_load_file("http://www.quidco.com/blog/?feed=rss2",'SimpleXMLElement', LIBXML_NOCDATA);
The errors i get are:
Quote:
Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:1: parser error : Start tag expected, '<' not found in [my php script]
Warning: simplexml_load_file() [function.simplexml-load-file]: 2977 in [my php script]
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in [my php script]
Any ideas or suggestions will be much appreciated thanks.
d.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: 4 Weeks Ago

re: simplexml_load_file problem


I'm stumped on this one. I don't get the same error as you.. I get:

Expand|Select|Wrap|Line Numbers
  1. Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:76: parser error : expected '>' in C:\xampp\htdocs\index.php on line 3
  2.  
  3. Warning: simplexml_load_file() [function.simplexml-load-file]: <link>http://www.quidco.com/blog/?p=365</li     <comments>http://www.quidco.com/b in C:\xampp\htdocs\index.php on line 3
  4.  
  5. Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
  6.  
  7. Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:76: parser error : Opening and ending tag mismatch: link line 76 and li in C:\xampp\htdocs\index.php on line 3
  8.  
  9. Warning: simplexml_load_file() [function.simplexml-load-file]: <link>http://www.quidco.com/blog/?p=365</li     <comments>http://www.quidco.com/b in C:\xampp\htdocs\index.php on line 3
  10.  
  11. Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
  12.  
  13. Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:327: parser error : Extra content at the end of the document in C:\xampp\htdocs\index.php on line 3
  14.  
  15. Warning: simplexml_load_file() [function.simplexml-load-file]: 0 in C:\xampp\htdocs\index.php on line 3
  16.  
  17. Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
Newbie
 
Join Date: Oct 2009
Posts: 2
#3: 4 Weeks Ago

re: simplexml_load_file problem


Markus,
Thanks for the reply. I've just tried loading the content to a local file via file_get_contents and have realised that it's a data problem - there are various control characters (e.g ^M) at the start and end of the xml. Previously i'd just copied the source from Firefox so hadn't seen those characters. Now i just have to figure out whether i can remove them, or persuade quidco to remove them. Thanks again.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: 4 Weeks Ago

re: simplexml_load_file problem


Quote:

Originally Posted by newzdog View Post

Markus,
Thanks for the reply. I've just tried loading the content to a local file via file_get_contents and have realised that it's a data problem - there are various control characters (e.g ^M) at the start and end of the xml. Previously i'd just copied the source from Firefox so hadn't seen those characters. Now i just have to figure out whether i can remove them, or persuade quidco to remove them. Thanks again.

I'd tell the site to produce valid XML :D
Reply