-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlparsertable.js
44 lines (33 loc) · 1004 Bytes
/
xmlparsertable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var https = require('https');
var parseString = require('xml2js').parseString;
var xml = '';
const converter = require('Json-2-csv');
const fs = require ('fs');
function xmlToJson(url, callback) {
var req = https.get(url, function(res) {
var xml = '';
res.on('data', function(chunk) {
xml += chunk;
});
// res.on('error', function(e) {
// callback(e, null);
// });
// res.on('timeout', function(e) {
// callback(e, null);
// });
res.on('end', function() {
parseString(xml, function(err, result) {
callback(null, result);
});
});
});
}
var url = "https://data.gov.in/sites/default/files/Date-Wise-Prices-all-Commodity.xml"
xmlToJson(url, function(err, data) {
if (err) {
return console.err(err);
}
var teststr = JSON.stringify(data, null, 2);
teststr = teststr.replace("soap:Envelope","soapEnvelope").replace("soap:Body","soapBody").replace("diffgr:diffgram","diffgrdiffgram");
console.log(teststr);
});