Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have written a webpage that takes in an xml file from an RSS and parses it by certain tags. I have tested it on a local copy of the data I am planning on using and it works fine. The catch is that I cannot figure out how to call an rss file on a different webpage and parse its data.

Here is my code for setting up the parser:

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", ".../NewsFeed.aspx?output=Atom", false);

Here is the header of the xml file I get when I inspect the RSS page:

<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
<title type="text"> News</title>
<subtitle type="text">A syndication of the most recently published news.</subtitle>

<id>uuid:64d61c8e-c5d7-4529-b5a3-2dcd4097238b;id=50</id>

<rights type="text">© 2013 <owner goes here>. All Rights Reserved.</rights>

<updated>2013-07-09T13:34:27Z</updated>

<link rel="alternate" href=".../Default.aspx" />
<link rel="self" href=".../NewsFeed.aspx" />

I edited the links for posting purposes. I have tried using both of the links listed in the RSS document as well as the URL to the external feed in the open xml method, but I had no luck.

 xmlhttp.open("GET", "link goes here", false);

Does anyone know how I would read the RSS feed? As a side note, the feed is a standard RSS feed (2.0) returned in atom format.

share|improve this question
    
YQL or yahoo pipes –  dandavis Jul 18 '13 at 19:13
    
I am not quite sure what you mean by either of those. I am not very familiar with the interaction of HTML/JS and XML –  user2517628 Jul 18 '13 at 19:16
    
when someone gives me a suggestion i've not heard of, the first thing i do is google it... –  dandavis Jul 18 '13 at 19:17
add comment

1 Answer

Two things to check for starters:

1) Your NewsFeed.aspx needs to be hosted at exactly the same protocol, sub-domain, domain, and port as the page calling it. Otherwise browser security kicks in and prevents you from using an XHR. If you're trying to read a 3rd party RSS feed you may need to use a proxy.

2) The content-type header of the response needs to be text/xml. There are ways to get around this, but it's better if the content-type is accurate.

share|improve this answer
    
In response to your first point, that is probably why it doesn't work. I am developing on a sandbox server and the RSS is on live. As for the second, I am not in control of how the XML/RSS is formatted so I have to work within its constraints –  user2517628 Jul 18 '13 at 19:28
    
Sounds like you need a proxy, I've had to do the same thing myself. Regarding the content-type, note it's a response header NOT part of the XML formatting. Response headers are set by the server, so if you get to a point where you can see it's incorrect, you'll have to talk to the server admin. –  murdock Jul 18 '13 at 20:00
    
You can also use Superfeedr's API with supports JSONP on feed retriveal :) –  Julien Genestoux Jul 18 '13 at 22:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.