You are here:  » xml feed with leading characters


xml feed with leading characters

Submitted by benny on Tue, 2006-03-21 21:26 in

I'm having problem parsing this url with Magic Parser. Worked fine in the demo, when I copy the url locally it works fine, but seems to be having a problem when I try to grab it from the server.

Here's the url:
http://www.inman.com/rss/customer/redwing/InmanNews.xml

Is there something wrong with the xml file? I was able to get it to work on the demo on the site though, so I would think that would mean that it must be something I am doing. Here's my code:

  require("MagicParser.php");
  function myRecordHandler($article)
  {
    print "<p>".$article["TITLE"]."<br />";
print "".$article["DESCRIPTION"]."<br />";
print "".$article["PUBDATE"]."<br />";
print "".$article["AUTHOR"]."</p>";
print "<div class='articlebody'".$article["BODY"]."</div>";
  }
  $url = "http://www.inman.com/rss/customer/redwing/InmanNews.xml";
  MagicParser_parse($url,"myRecordHandler","xml|CHANNEL/ITEM/");
 //my local test that functions
 //MagicParser_parse("inman.xml","myRecordHandler","xml|CHANNEL/ITEM/");

Any help would be greatly appreciated.

Submitted by support on Tue, 2006-03-21 21:31

Hi,

This is almost certainly down to URL wrappers not being enabled on your server. To verify this, can you modify your PHP as follows; and this will display the PHP error when trying to open the feed. If this is the case, i'll help you through getting it enabled so that you can read the feed via URL:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($article)
  {
    print 
"<p>".$article["TITLE"]."<br />";
    print 
"".$article["DESCRIPTION"]."<br />";
    print 
"".$article["PUBDATE"]."<br />";
    print 
"".$article["AUTHOR"]."</p>";
    print 
"<div class='articlebody'".$article["BODY"]."</div>";
  }
  
$url "http://www.inman.com/rss/customer/redwing/InmanNews.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|CHANNEL/ITEM/");
  print 
MagicParser_getErrorMessage();
?>

It's that last line that will print the error message - can you let me know what it says and we'll take it from there...

Submitted by benny on Tue, 2006-03-21 21:38

Thanks for the quick reply. Unfortunately, when I run that, I don't receive any errors!

Submitted by support on Tue, 2006-03-21 21:48

Ok, one way to test it out is to use fopen directly:

<?php
  error_reporting
(E_ALL);
  
$url "http://www.inman.com/rss/customer/redwing/InmanNews.xml";
  
$fp fopen($url,"r");
  
$text fgets($fp,10);  
  print 
"[".$text."]";
  
fclose($fp);
?>

This should set error_reporting to the max when trying to open the feed using URL wrappers, so we should be able to see what is going on as it is possible that your PHP configuration has errors and warnings disabled...

Submitted by benny on Tue, 2006-03-21 21:48

I can get the bbc example you have posted in the manual to work properly as well as other RSS/XML feeds. The odd thing is that when I run the demo on your website, it pulls the data in. When I grab the source xml off of that feed and save it locally, it runs with no problems. However, when I try to grab that file on Inman's server, I receive absolutely nothing on the page. :(

Submitted by benny on Tue, 2006-03-21 21:49

this is all I receive on the new code on the screen you posted up:

[

when looking at the source, I get this:
[<?xml ]

Submitted by support on Tue, 2006-03-21 21:53

I get the same result here. At least it means that URL wrappers are enabled on your server so we should be able to get you working easily.

I think it's a case of character encoding not being detected correctly. Let me run a quick test and i'll get back to you...

Submitted by benny on Tue, 2006-03-21 21:56

thanks for all your help!

Submitted by support on Tue, 2006-03-21 22:11

Hi,

Please check your email for the fixed encoding versions of MagicParser which should help; if not; I have included a special version which will skip over the leading characters...