I am trying to export a function which will parse a xml to json object.
export const parse = (body) => {
const parser = new xml2js.Parser({explicitArray: false, trim: true});
parser.parseString(body, (err, result) => {
if (err) return err;
parser.parseString(result['soapenv:Envelope']['soapenv:Body']['ns1:searchResponse'].searchReturn._, (err, result) => {
if (err) return err;
console.log(result);
return result;
});
});
}
The problem I am having is that the function returns undefined, however, it manages to console.log the correct result.