michaelkourlas / node-js2xmlparser

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

Attributes in root element #58

Closed kkoteeswaran closed 7 years ago

kkoteeswaran commented 7 years ago

I would like to build a XML request that looks like this:

<?xml version='1.0'?>
<person type="owner">
    <firstName>John</firstName>
    <lastName>Smith</lastName>
</person>

with attribute type="owner" in the root element. Is there a way to do that?

dsych commented 7 years ago

Based on this example you can just say:

let person = {
    "@":{
        "type": "owner"
     },
    "firstName": "John", 
    "lastName": "Smith"
}

console.log(js2xmlparser.parse("person", person));
andresjuarez commented 7 years ago

Excellent I had the same doubt! Thanks @dsych you are the man. I would close this issue

kkoteeswaran commented 7 years ago

Thank you!