Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Created October 11, 2013 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonrhodes/6942015 to your computer and use it in GitHub Desktop.
Save jasonrhodes/6942015 to your computer and use it in GitHub Desktop.
Trying to read XML from a search API and convert it to JSON.
var http = require('http');
var xmld = require('xml2js');
var express = require('express');
var app = express();
// app.use(express.static(__dirname + '/public'));
app.get("/", function (req, res) {
var options = {
hostname: "search.mysite.com",
path: '/search?site=hub&client=hub_frontend&output=xml_no_dtd&q=cats'
};
var gsaReq = http.get(options, function (response) {
response.on('data', function (chunk) {
console.log(chunk);
// xmld.parseString(chunk, function (err, result) {
// if (err) console.log("ERROR", err);
// console.log('my resultsult', result);
// });
});
}).on('error', function (e) {
console.log('problem with request: ' + e.message);
});
});
app.listen(3000);
@psi-4ward
Copy link

   var gsaReq = http.get(options, function (response) {
var xmlstr = '';
        response.on('data', function (chunk) {
            xmlstr += chunk.toString();
            // xmld.parseString(chunk, function (err, result) {

            //     if (err) console.log("ERROR", err);

            //     console.log('my resultsult', result);

            // });
        });
    }).on('error', function (e) {
        console.log('problem with request: ' + e.message);
    }).on('end', function() { console.log(xmlstr);}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment