Trying to read XML from a search API and convert it to JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
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
Sometimes line 17 prints out what looks like an XML string (what I expect) but sometimes it prints out lines like this:
I'm not sure how to receive the data from the request, that should be an XML string, and make sure I have that string so I can convert it into JSON and push it into a template... help?