Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
xml2js - parserString function return value

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);```
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!