[SOLVED] Parsing XML from remote URL

I’ve been trying to parse a remote XML URL, basically just something totally plain like this:

I use HTTP.get() to make the request and I’m trying to parse the XML into a client-side collection. Any pointers on how to do this? I’m using XML2Js and it looks like this:

Meteor.publish('episodeSearch', function() {
	var self = this;

	try {
		var response = HTTP.get("http://www.npr.org/rss/podcast.php?id=510307");

		// parse
		xml2js.parseString(response, function (err, result) {

	catch(error) {

And it just keeps returning undefined.

Is the GET request actually returning a response?

Yeah it is. For now I just ended up using Google’s Feed API to convert it to JSON but would love to be able to properly parse the XML.

You probably want to use:

xml2js.parseString(response.content, function (err, result) {

At least, that’s the gist of what I’m using in one of my apps (I’m actually using the synchronous version):

var result = xml2js.parseStringSync(response.content);
// do stuff with results

Which works great.


Yup, the answer is that you’re passing the whole response object instead of its content property value, which is where the response’s content actually resides. That’s the difference in the code in the answer above!

1 Like