Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best JSON or JS object to XML converter module for Node JS [closed]

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:

  • https://github.com/davidcalhoun/jstoxml
  • https://github.com/soldair/node-jsontoxml
  • https://github.com/QuickenLoans/node-easyxml
  • https://github.com/michaelkourlas/node-js2xmlparser

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> 
like image 235
Christiaan Westerbeek Avatar asked Jun 19 '14 14:06

Christiaan Westerbeek


People also ask

What is the difference between JSON and node JS?

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.

How does node js work with XML?

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.

Does node require package JSON?

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.


1 Answers

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:

  • chilts/data2xml
  • oozcitak/xmlbuilder-js

The latter is by far the most matured and downloaded on npm. It allows you to build XML in one go or iteratively.

like image 65
Christiaan Westerbeek Avatar answered Oct 10 '22 07:10

Christiaan Westerbeek