I need to build a relatively simple XML document with some hierarchy and some attributes from a JS object. I stand now before choosing one of these modules:
Which module should I pick?
This question will probably be dismissed as being not a good question, but I don't know how to ask it any differently.
Disclaimer: I posted the same question as an issue on each repository
This is the XML that I want to build:
<?xml version="1.0" encoding="UTF-8"?> <orders> <order> <order_orderid>123123</order_orderid> <order_customerid>345345</order_customerid> <order_senhcode>7604</order_senhcode> <order_mediacode>qwert</order_mediacode> <order_totalshippingcost>0</order_totalshippingcost> <order_paymentmethod>GB</order_paymentmethod> <order_paymentnumber /> <order_htmltext /> <order_comment /> <shippingmethodid>02</shippingmethodid> <order_creditcardnumber /> <order_creditcardnameholder /> <order_creditcardexpiredate /> <order_creditcardsafetycode /> <order_gifttext /> <inv_customer> <inv_customer_addresstypeid /> <inv_customer_gendermale>0</inv_customer_gendermale> <inv_customer_firstname>qwerty</inv_customer_firstname> <inv_customer_initials>Q.W.E</inv_customer_initials> <inv_customer_prename /> <inv_customer_lastname>Qwerty</inv_customer_lastname> <inv_customer_company>Some company</inv_customer_company> <inv_customer_street>Postbus</inv_customer_street> <inv_customer_housenumber>13</inv_customer_housenumber> <inv_customer_housenumberadditional /> <inv_customer_postalcode>1234 AB</inv_customer_postalcode> <inv_customer_city>THERE</inv_customer_city> <inv_customer_isocodecountry>NL</inv_customer_isocodecountry> <inv_customer_email>[email protected]</inv_customer_email> <inv_customer_telephone>0168-123456</inv_customer_telephone> <inv_customer_mobilenr>06-12345678</inv_customer_mobilenr> </inv_customer> <orderlines> <orderline> <orderline_orderrecordid>1234</orderline_orderrecordid> <orderline_orderid>8765432</orderline_orderid> <orderline_articlenr>164-05-366</orderline_articlenr> <orderline_quantity>2</orderline_quantity> <orderline_productdescription>Some gift voucher</orderline_productdescription> <orderline_price>1233</orderline_price> </orderline> <orderline> <orderline_orderrecordid>5678</orderline_orderrecordid> <orderline_orderid>8765432</orderline_orderid> <orderline_articlenr>164-05-367</orderline_articlenr> <orderline_quantity>3</orderline_quantity> <orderline_productdescription>Some other gift voucher</orderline_productdescription> <orderline_price>1244</orderline_price> </orderline> </orderlines> </order> </orders>
With node. js as backend, the developer can maintain a single codebase for an entire application in javaScript. JSON on the other hand, stands for JavaScript Object Notation. It is a lightweight format for storing and exchanging data.
Node. js has no inbuilt library to read XML. The popular module xml2js can be used to read XML. The installed module exposes the Parser object, which is then used to read XML.
The package. json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.
I investigated myself
| author | davidcalhoun | soldair | QuickenLoans | michaelkourlas | |---------------|--------------|-----------|--------------|----------------| | module | jstoxml | node- | node- | node- | | | | jsontoxml | easyxml | js2xmlparser | | Commits | 31 | 64 | 39 | 61 | | Recent commit | a year ago | 2 years ag| 6 months ago | 16 days ago | | Contributors | 2 | 7 | 7 | 6 | | Issues | 16 | 19 | 17 | 15 | | Open Issues | 7 | 1 | 6 | 1 | | npm install | jstoxml | not found | easyxml | js2xmlparser | | Dependencies | None | None | elementtree, | None | | | | | inflect | | | Throws errors | None | None | 3 | 12 |
Then there's the type of objects required to compare
davidcalhoun/jstoxml:
{ "_name": 'foo', "_content": 'bar', "_attrs": { "a": 'b', "c": 'd' } }
soldair/node-jsontoxml: looks complicated
QuickenLoans/easyxml:
items: [{ "name": 'one', "_id": 1 }, { "name": 'two', "_id": 2 } ]
michaelkourlas/node-js2xmlparser
foo: { "#": 'bar', "@": { a: 'b', c: 'd' } }
I think I'll give michaelkourlas's node-js2xmlparser a shot.
Update: It seems now that there are 2 more worth mentioning:
The latter is by far the most matured and downloaded on npm. It allows you to build XML in one go or iteratively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With