2

I am using a very cool php library(whatever it is called) called SimplePie. I am using the latest version.

I have this code:

$url = 'http://www.seobook.com/feeds.shtml';
$SimplePieFeed->set_feed_url($url);
$SimplePieFeed->force_feed(true);
$SimplePieFeed->enable_order_by_date(true);
$success = $SimplePieFeed->init();
if( !$SimplePieFeed->error() ) {
    foreach( $SimplePieFeed->get_items() as $item ) {
      ......
    }
} else {
    print_r( $SimplePieFeed->error() );
}

Why is it that when I run this code I'm getting this kind of error:

This XML document is invalid, likely due to invalid characters. XML error: not well-formed (invalid token) at line 8, column 76

I try to run this one on Simplepie's demo and everything is going well. Why is it that when I run it on my end i'm having that kind of error? Is it because of a cache? I noticed that Simplepie is storing feeds in a cache. I have tried $SimplePieFeed->enable_cache(false); but still i'm getting that error. I'm not even sure if that's related to that kind of error. LOL!

Your help would be greatly appreciated and rewarded! :Thank you very much!

hakre
  • 193,403
  • 52
  • 435
  • 836
PinoyStackOverflower
  • 5,214
  • 18
  • 63
  • 126
  • Different sites use different request headers. A first step if you don't want to compare all these would be to take the *actual* feed URL: http://www.seobook.com/rss.xml - at least the XML validates then: http://validator.w3.org/appc/check.cgi?url=http%3A%2F%2Fwww.seobook.com%2Frss.xml – hakre Dec 13 '12 at 06:42
  • @hakre This is a user input, do you have any idea how to ensure that the user inputted an actual Feed URL? – PinoyStackOverflower Dec 13 '12 at 06:44
  • Well if you are not able to communicate to the user what you need, you are doomed. At least for the simple input processing. If the user is too dumb, the user is too dumb. Check what happens with the simplepie demo application, check the request if you can. They might have the sources of it on their website. – hakre Dec 13 '12 at 06:45
  • 1
    From $SimplePieFeed->force_feed(true); I changed it into $SimplePieFeed->force_feed(false) then the error was gone. But i'm still not satisfied with the reason behind this. I got a feeling that I will get an inconsistent result by doing that one. Hmmm... – PinoyStackOverflower Dec 13 '12 at 06:52
  • 1
    That setting enables auto-discovery. Go for it, it's the user-friendly variant to be generous with input. You won't get inconsistent results by doing that one, its quite tested over the years. – hakre Dec 13 '12 at 06:54
  • 1
    Ok then.haha! This is funny. Thanks for your answer. I thought you were part of SimplePie Dev team because everytime I asked about SimplePie question you're always the one who keeps on answering. Lol! :) – PinoyStackOverflower Dec 13 '12 at 06:56

1 Answers1

1

Simple there is problem in your xml file you should remake the .xml file,if you are using wordpress simple use plugin called google site maps its pretty good.

If you using some thing else like php, or html base site you should make valid xml document maker like some listed here,

xml-sitemaps.com
xmlgrid.net   (editor viewer)
web-site-map.com

May it help you little in your case.

user2180101
  • 117
  • 1
  • 2
  • 7