我已經寫了下面的代碼讀取XML,並返回一個HashMap:的NodeJS:類型錯誤:回調不是一個函數
this.xmlObjectRepositoryLoader = function (xmlPath, callback){
var map = {}
var innerMap = {};
var el;
fs.readFile(xmlPath, "utf-8",function(err, data) {
if(err){
console.log('File not found!!')
}
else{
console.log(data)
var doc = domparser.parseFromString(data,"text/xml");
var els = doc.getElementsByTagName("Child");
for(var i =0 ; i< els .length;i++){
var e = elements[i];
eName = e.getAttribute("a");
var params = elm.getElementsByTagName("abc");
innerMap = {};
for(var j =0 ; j< params.length;j++){
var param = params[j];
var b = param.getAttribute("b");
var c= param.getAttribute("c");
innerMap[b] = c;
}
map[el] = innerMap;
innerMap={};
};
}
console.log(map);
return callback(map);
});
};
我打電話來從下面的方法xmlObjectRepositoryLoader
但它返回的錯誤爲TypeError: callback is not a function
:
this.objectLoader = function(filePath){
if (filePath.includes(".xml")) {
console.log(this.xmlObjectRepositoryLoader(filePath));
}
能否請您讓我知道我錯了,我怎麼能解決這個
希望在投降之前,人們應該也有理由相信。反正謝謝你看看。 – Abhinav