我有这样一个存储了配置信息的xml文件:
读取这个配置文件的JavaScript代码,使用了nodejs里的xml2js模块:
const fs = require('fs');
var path = require('path');
var configPath = path.join(__dirname, 'koiFieldList.xml');
var configString = fs.readFileSync(configPath, 'utf8');
var parseString = require('xml2js').parseString;
var siteDedicatedList = require("./sourceDedicatedFieldList.json");
function getAllFieldList(callback){
parseString(configString, function (err, result) {
if(err)
throw err;
callback(result);
});
}
module.exports = {
getAllFieldList: getAllFieldList
};
如何消费这个getAllFieldList?
var koiFieldListAccessTool = require("../../control/koiFieldListAccessTool.js");
koiFieldListAccessTool.getAllFieldList(function(result){
console.log(result);
}
);
- 1
- 2
- 3
- 4
- 5
- 6
测试结果,能够正常工作:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":