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

187
Vistas
xml2js parser ignores the empty string in an array resulting in array size change

xml below to be parsed:

<ENVELOPE>
<ABC>
    <DEF>apple</DEF>
    <GHI>4</GHI>
    <JKL>85</JKL>
</ABC>
<MNO>add</MNO>
<PQR></PQR>
<STU></STU>
</ENVELOPE>

and response after parsing:

{

"ENVELOPE": { "ABC": { "DEF": "apple", "GHI": "4", "JKL": "85" }, "MNO": "add" } }

The other two tags has been discarded by the xml2js parses. But i need it there to be empty atleast. Have tried using options of the parser but no luck yet

Here is my code to get the parser:

private getParser() {
let nameToLowerCase = (name: string): string => {
  return name.toLowerCase();
}

let options: xml2js.Options = {
  attrkey: '_',
  charkey: '$',
  explicitCharkey: true,
  emptyTag: null,
  normalize: true,
  normalizeTags: true,
  explicitArray: false,
  trim: true,
  tagNameProcessors: [nameToLowerCase],
  attrNameProcessors: [nameToLowerCase]
};

return new xml2js.Parser(options);

}

over 4 years ago · Santiago Trujillo
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