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

80
Visualizações
Extracting information from XML using Javasript

I have a word file saved as an XML file and I wanted to extract all the information between <w:t> tags. This is the piece of code I am using.

//var parser = new DOMParser();
const fs = require('fs');
const { connect } = require('http2');
var format = require('xml-formatter');
try {
    // read contents of the file
    const data = fs.readFileSync('untitled.xml', 'UTF-8');
    //var d = format(data);

    // split the contents by new line
    const lines = data.split(/\r?\n/);

    // print all lines
    lines.forEach((line) => {
        if(/<w:t>.*:.*<\/w:t>/.test(line)){
            console.log(line);
            // var match = line.match(/<w:t>Comment:.*<\/w:t>/g);
            // console.log(match);
            // console.log('ASDRWSGQERGEAHGERAGERgfew');
        }
    });
    
} catch (err) {
    console.error(err);
}

The problem is that as the tree structure of the XML is not preserved while I'm reading it the output tends to have a lot of unnecessary lines in it. When I copy-paste the same file from a browser and save it as an XML, the output is clean. Is there another way to read the XML to get a clean output? current garbage output

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