Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!