Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Handling of Whitespaces & Line breaks #177

Open
Kr0san89 opened this issue Nov 5, 2021 · 1 comment
Open

Wrong Handling of Whitespaces & Line breaks #177

Kr0san89 opened this issue Nov 5, 2021 · 1 comment

Comments

@Kr0san89
Copy link

Kr0san89 commented Nov 5, 2021

If we add inside an XML-Element instead of Characters, Linebreaks or Whitespaces, this information get's lost by converting it to JSON. See the Example, if we add inside the tag "foo" an string "bar", we get the correct JSON as we would expect, but if we swap it with a linebreak or whitespace, the information of the Linebreaks / Whitespaces is lost and the JSON looses the sub elements.

Current Behaivour:
`

var convert = require('xml-js');
undefined
convert.xml2json('bar')
'{"elements":[{"type":"element","name":"foo","elements":[{"type":"text","text":"bar"}]}]}'
convert.xml2json('\n')
'{"elements":[{"type":"element","name":"foo"}]}'
convert.xml2json(' ', {trim: false})
'{"elements":[{"type":"element","name":"foo"}]}'`

Expected Behaivour:
`

var convert = require('xml-js');
undefined
convert.xml2json('bar')
'{"elements":[{"type":"element","name":"foo","elements":[{"type":"text","text":"bar"}]}]}'

convert.xml2json('\n')
'{"elements":[{"type":"element","name":"foo","elements":[{"type":"text","text":"\n"}]}]}'
convert.xml2json('\n', {trim: true})
'{"elements":[{"type":"element","name":"foo"}]}'

convert.xml2json(' ', {trim: false})
'{"elements":[{"type":"element","name":"foo","elements":[{"type":"text","text":" "}]}]}'
convert.xml2json(' ', {trim: true})
'{"elements":[{"type":"element","name":"foo"}]}'
`

I also tried the trim option but it didn't effect this.

@ktkhang
Copy link

ktkhang commented Nov 30, 2021

I also got this same error. This is a bug. Hope to get help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants