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

221
Visualizações
Parsing XML elements without closing tags in JavaScript

I am running into a problem with the fast-xml-parser npm package. I'm trying to parse some XML from an external source that has a series of elements with self closing tags but those elements have data in them that I need. Consider the following snippet:

const options = {
    unpairedTags: ["link"]
};
const parser = new XMLParser(options);
const obj = parser.parse('<link something="idc" data="i care about this data"/>');

You can see that I have tried adding an unpaired tag but obviously this doesn't work because the idc and data properties are not considered XML so obj still lands up being blank

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The default is to ignore attributes. Set the parse option ignoreAttributes

const options = {
  unpairedTags: ["link"],
  ignoreAttributes : false
};

https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md

about 4 years ago · Juan Pablo Isaza Relatório
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