Quick tip on changing XML to JSON for easier parsing of feeds. So I’m at work trying to bring in an RSS feed and parse it onto the site. But every time I try, I get an error. The response is OK but there is no data in the XML object. So after some digging around I find that its a bit hit and miss using xml cross domain. If the headers haven’t been set correctly then the object response will be empty and we get this message in firebug. So what’s the answer?? Google is the answer to all our problems!!! Or to be more precise the Google Feed API. This just takes all the hassle out of it.
Change XML to JSON with Google Feed API
If you are like me and think that all cross domain stuff should be done with JSON and just love to work with it then this is the method for you. So for the example, in a bout of shameful promotion, we’ll use my own RSS feed. Now this could be the original feed or as we’re going to use my feedburner feed. To create a feedburner feed you create an account then add the url’s of the feeds you want to burn and they in turn give you a feedburner url which you can promote. Why do this? Well if you have a lot of people follow your rss then feedburner is ideal as it caches the feed thus creating less strain on your server. Also there are lots of tracking options so you can see at a glance how many people have signed up to your feed.
Convert XML to JSON
the q= at the end of this url means the next peice of the url is a query an this bit is our feed url
I’m not going to show you the CSS because it is not relevant to this post.
Next in the parse_res function we create a variable that hold all the entries from the feed (basically this is all the post information. then we get the div with the id of post_results and put that in a variable. Then we create and unordered list element (these are all our containers.). then we create a for loop and for each of our posts we create a li tag, an a tag and we populate these with links and titles from the feed. then we append these to the unordered list and the add that to the container variable.