I am trying to return the result value of the parseString. I am able to console.log result but return value is undefined. I am trying to parse the xml and assign each value to a variable. I saw some of the older posts with async/await which is used for calling the processResult function but that did not work out. Any help is appreciated.
import readXMLFile from '../readFile.js';
import * as xml2js from 'xml2js';
import * as util from 'util';
const xmlsourcedata = readXMLFile('./src/helpers/parserXML/00a03_e.xml');
//console.log(xmlsourcedata);
var stripNS = xml2js.processors.stripPrefix;
const parserOpts = {
async: true,
normalize: true,
normalizeTags: true,
explicitArray: false,
explicitRoot: false,
strict: false,
xmlns: false,
tagNameProcessors: [stripNS]
};
const processResult = (xml) => {
try {
var parser = new xml2js.Parser(parserOpts);
parser.parseString(xml.toString(), function(err,result) {
//console.log(JSON.stringify(result));
console.log(util.inspect(result, false, {depth: null}));
return result;
});
}
catch (error) {
console.error(`Got processing error ${error.message}`);
}
}
processResult(xmlsourcedata);```