michaelkourlas / node-js2xmlparser

Popular Node.js module for parsing JavaScript objects into XML
https://www.npmjs.org/package/js2xmlparser
Apache License 2.0
222 stars 52 forks source link

Can't use 'length' in complex usage #77

Closed javierugarte closed 5 years ago

javierugarte commented 5 years ago

When I try to use the property length in complex use, It don't create the xml correctly.

Error:

already contains an attribute with the name "length"

It is because, when using an array / object, the length property already exists.

Escape this word? Replace and then back again?

Example:

var example2 = function() {
    var obj = {
        "name": "John",
        "phone": [
            {
                "@": {
                    "length": "home"
                },
                "#": "123-555-4567"
            }
        ],
        "email": "john@smith.com"
    };
    console.log(js2xmlparser.parse("person", obj));
    console.log();
};
example2();

Regards

michaelkourlas commented 5 years ago

This was a bug in xmlcreate which is now fixed. If you run npm update you should pick up the new version and the problem should be fixed.