Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda