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

Builder : #text is not set as tag value when some attributes are present #521

Closed benjamin-feron closed 1 year ago

benjamin-feron commented 1 year ago

Hi everybody ! I've a little issue with this lib, can someone help me ?

Description

text is ignored when other attributes exists

Code

import { XMLBuilder } from 'fast-xml-parser'

const xmlData = {
  "tag1": {
    "#text": "aaa"
  },
  "tag2": {
    "#text": "aaa",
    "attr": "bbb"
  }
}

const xmlBuilder = new XMLBuilder({
  attributeNamePrefix: '',
  format: true,
  ignoreAttributes: false
})

const xml = xmlBuilder.build(xmlData)

console.log(xml)

Output

<tag1 #text="aaa">aaa</tag1>
<tag2 #text="aaa" attr="bbb"></tag2>

Expected data

<tag1 #text="aaa">aaa</tag1>
<tag2 #text="aaa" attr="bbb">aaa</tag2>

Test this code

You can test this code here

Would you like to work on this issue?

Thanks !

github-actions[bot] commented 1 year ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 1 year ago

Did you try to set textNodeName?

benjamin-feron commented 1 year ago

Yes but it does not change anything.

Thank you

amitguptagwl commented 1 year ago

show me the configuration you tried with textNodeName

amitguptagwl commented 1 year ago

closing the issue. If it still exist, please reopen with sample code.