buglabs/node-xml2json

position of $t property is matter for XML generation

iuriifavi opened this issue · 2 comments

xml2json.toXml({ShippingServiceAdditionalCost: { '$t': 0, currencyID: 'USD' } }})
==
"<ShippingServiceAdditionalCost>0 currencyID="USD"</ShippingServiceAdditionalCost>"

and

xml2json.toXml({ShippingServiceAdditionalCost: { currencyID: 'USD', '$t': 0 } }})
==
"<ShippingServiceAdditionalCost currencyID="USD">0</ShippingServiceAdditionalCost>"

hmm, interesting. It looks like a bug indeed.

ToXml.prototype.parse = function(obj) {
var self = this;
var keys = Object.keys(obj);
var len = keys.length;

// Sub node should be moved to the end
keys.sort(_ => _ == '$t');