NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.49k stars 302 forks source link

ignoreAttributes breaks unpairedTags #540

Closed croghostrider closed 1 year ago

croghostrider commented 1 year ago

Description

Hi @amitguptagwl, i found the problem with the unpairedTags parameter. If i set ignoreAttributes to false the paramter unpairedTags is ignored. ### Input

Code

const { XMLParser, XMLBuilder } = require('fast-xml-parser')
const xmlData = `
<CommunicationLog xmlns="http://knx.org/xml/telegrams/01">
 <Telegram Timestamp="2023-01-29T23:01:06.239Z" RawData="0640103020080ee"/>
 <Telegram Timestamp="2023-01-29T23:01:16.945Z" RawData="0640103020080aa"/>
 <Telegram Timestamp="2023-01-30T22:58:27.572Z" RawData="066040c02008067"/>
 <Telegram Timestamp="2023-01-30T22:58:27.606Z" RawData="066043402008067"/>
</CommunicationLog>`

const options = {
  format: true,
  ignoreAttributes: false,
  suppressUnpairedNode: false,
  unpairedTags: ['Telegram']
}
const parser = new XMLParser(options)
const result = parser.parse(xmlData)

const builder = new XMLBuilder(options)
const output = builder.build(result)
console.log(output)

Output

<CommunicationLog xmlns="http://knx.org/xml/telegrams/01">
  <Telegram Timestamp="2023-01-29T23:01:06.239Z" RawData="0640103020080ee"></Telegram>
  <Telegram Timestamp="2023-01-29T23:01:16.945Z" RawData="0640103020080aa"></Telegram>
  <Telegram Timestamp="2023-01-30T22:58:27.572Z" RawData="066040c02008067"></Telegram>
  <Telegram Timestamp="2023-01-30T22:58:27.606Z" RawData="066043402008067"></Telegram>
</CommunicationLog>

expected data

<CommunicationLog xmlns="http://knx.org/xml/telegrams/01">
 <Telegram Timestamp="2023-01-29T23:01:06.239Z" RawData="0640103020080ee"/>
 <Telegram Timestamp="2023-01-29T23:01:16.945Z" RawData="0640103020080aa"/>
 <Telegram Timestamp="2023-01-30T22:58:27.572Z" RawData="066040c02008067"/>
 <Telegram Timestamp="2023-01-30T22:58:27.606Z" RawData="066043402008067"/>
</CommunicationLog>

Would you like to work on this issue?

Bookmark this repository for further updates.

amitguptagwl commented 1 year ago

fixed