nashwaan / xml-js

Converter utility between XML text and Javascript object / JSON text.
MIT License
1.29k stars 181 forks source link

Empty String of nativeTypeAttributes converted zero #198

Open cagriman opened 1 year ago

cagriman commented 1 year ago

Hello,

With nativeTypeAttributes = true configuration transformation of json to xml, getting some invalid result as explained that xml attribute valued as Empty String converted to Zero as Number.

Could you fix it ?

Thanks

cagriman commented 1 year ago

Hello,

I solved my problem with adding below option to options.

attributeValueFn: (val: any) => (val === 0) ? '' : val

Issue can be close.

Thanks

cagriman commented 1 year ago

Hello,

But this function replace all zeros to string empty :) I mean this method runs after conversion not before :(

Sample XML ====> Result JSON =====> { "test:": { "_attributes" : { "att1": 0, "att2": 0 } } } Expected JSON ===> { "test:": { "_attributes" : { "att1": "", "att2": 0 } } }

Jzeemo commented 8 months ago

I am having the same issue.