-
-
Notifications
You must be signed in to change notification settings - Fork 342
Description
- [ x ] Are you running the latest version?
- [ x ] Have you included sample input, output, erro
r, and expected output?
- [ x ] Have you checked if you are using correct configuration?
- [ x ] Did you try online tool?
- [ x ] Have you checked the docs for helpful APIs and examples?
Description
Oddly, the online tool parses it successfully, but freshly-installed from npm (version 5.3.3) crashes and burns (node.js 25.2.1):
Input
See attached file.
Code
const fxp = require("fast-xml-parser");
const fs = require("node:fs");
const text = fs.readFileSync("fast-xml-parser-chokes.xml", "utf8");
const parser = new fxp.XMLParser({ attributeNamePrefix: '$', ignoreAttributes: false, removeNSPrefix: true });
const parsed = parser.parse()
console.log("XML has been parsed")
for (let element of parsed.ObservationCollection.member.Observation.result.elements) {
console.log("name = %s, value = %s, uom = %s", element.$name, element.$value, element.$uom)
}Output
TypeError: Cannot read properties of undefined (reading 'toString')
at tt.parse (/Users/davidb/temp/wx/node_modules/fast-xml-parser/lib/fxp.cjs:1:22589)
at doParse (/Users/davidb/temp/wx/wx2.js:59:27)
at /Users/davidb/temp/wx/wx2.js:47:9
at Generator.next ()
at fulfilled (/Users/davidb/temp/wx/wx2.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
expected data
XML has been parsed
name = data_avail, value = 100, uom = %
name = max_batry_volt_pst1hr, value = 11.72, uom = V
name = min_batry_volt_pst1hr, value = 11.64, uom = V
name = logr_panl_temp, value = 10.1, uom = °C
name = air_temp, value = 9.3, uom = °C
name = rel_hum, value = 79, uom = %
name = avg_air_temp_pst1hr, value = 9.4, uom = °C
name = max_air_temp_pst1hr, value = 9.8, uom = °C
name = max_rel_hum_pst1hr, value = 82, uom = %
name = min_air_temp_pst1hr, value = 9.1, uom = °C
name = min_rel_hum_pst1hr, value = 79, uom = %
[and so on]
Would you like to work on this issue?
- Yes
- [ x ] No
Bookmark this repository for further updates. Visit SoloThought to know about recent features.