0

So I have NodeJS and installed the module xml2js. In the tutorial we have an example taking an xml file from directory and convert it with JSON.stringify() as in the example. Now is there a possibility instead of calling the local xml file (foo.xml), to call a url of XML service for ex: www.wunderground.com/city.ect/$data=xml

var parser = new xml2js.Parser(); 
parser.addListener('end', function(result) {
    var res = JSON.stringify(result);   
        console.log('converted'); 
}); 
fs.readFile(__dirname + '/foo.xml', function(err, data) {
    parser.parseString(data); 
});
Artyom Neustroev
  • 8,627
  • 5
  • 33
  • 57
user2423027
  • 1
  • 1
  • 1

1 Answers1

1

You need to create an http request instead of reading a file. Something like this, I think:

http.get("http://www.google.com/index.html", function(res) {
  res.on('data', function (chunk) {
    parser.parseString(chunk); 
  });
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});

http://nodejs.org/api/http.html#http_http_request_options_callback

flyingjamus
  • 3,975
  • 2
  • 16
  • 13