-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (30 loc) · 886 Bytes
/
index.js
File metadata and controls
34 lines (30 loc) · 886 Bytes
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
var dumper = require('./jkl-dumper');
var xotree = require('./ObjTree');
module.exports.xml2json = function(xml,callback) {
var tree = xotree.parseXML(xml);
var result = dumper.dump(tree);
if(!callback) return result;
else callback(result);
}
module.exports.json2xml = function(json,isRSS,callback) {
if(typeof(json) == "string") var json = JSON.parse(json);
if(isRSS) var result = xotree.writeRSS(json);
else var result = xotree.writeXML(json);
if(!callback) return result;
else callback(result);
}
module.exports.requestHTTP = function(url, callback) {
var http = require('http');
http.get(url, function(res) {
var result = "";
res.on('error', function (e) {
//error handler
});
res.on('data', function(chunk) {
result += chunk;
});
res.on('end', function(){
callback(result);
});
});
};