buglabs / node-xml2json

Converts XML to JSON using node-expat
808 stars 209 forks source link

Xml parsing leaving off attribute #37

Closed davidleureka closed 10 years ago

davidleureka commented 11 years ago

var x = '<node1><node2 a="1">v1</node2></node1>'; parser.toJson(x); '{"node1":{"node2":{"a":1,"$t":"v1"}}}' var j = '{"node1":{"node2":{"a":1,"$t":"v1"}}}'; parser.toXml(j); '<node1><node2>v1</node2></node1>'

What happened to the attribute "a"?

c4milo commented 11 years ago

confirmed, thanks for reporting it!

markwedmunds commented 11 years ago

Hi, is there any update on this issue?

joe-herman commented 10 years ago

Line 24 of json2xml.js omits numbers, which causes them to be skipped:

if (typeof(obj[key]) == 'string' || isArray) {

and instead read should read:

if (typeof(obj[key]) == 'string' || isArray || typeof(obj[key]) == 'number') {

As a workaround you'd have to convert all numbers to strings.

idy commented 10 years ago

Could you pls fix this issue by @Penryn's suggestion? Or I could sent a PR. Thanks

c4milo commented 10 years ago

@idy a PR would be very well received, thanks!

idy commented 10 years ago

@c4milo This issue should be closed ;)

c4milo commented 10 years ago

Closed by 6bef41462bdf11762df4d9a96f04fb03e251b1f5 thanks @idy!