Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda