什么是最好的JSON或JS对象到XML转换模块的Node JS
What's the best JSON or JS object to XML converter module for Node JS
我需要从JS对象构建一个具有一些层次结构和一些属性的相对简单的XML文档。我现在站在这里选择其中一个模块:
- https://github.com/davidcalhoun/jstoxml
- https://github.com/soldair/node-jsontoxml
- https://github.com/QuickenLoans/node-easyxml
- https://github.com/michaelkourlas/node-js2xmlparser
我应该选择哪个模块?
这个问题可能会被认为不是一个好问题,但我不知道该怎么问。
免责声明:我在每个存储库
上发布了相同的问题。这是我要构建的XML:
<?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>a@b.nl</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>
我调查了一下自己
| 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 |
然后是需要比较的对象类型
davidcalhoun/jstoxml:
{
"_name": 'foo',
"_content": 'bar',
"_attrs": {
"a": 'b',
"c": 'd'
}
}
soldair/node-jsontoxml:看起来很复杂
QuickenLoans/easyxml:
items: [{
"name": 'one',
"_id": 1
}, {
"name": 'two',
"_id": 2
}
]
michaelkourlas/node-js2xmlparser
foo: {
"#": 'bar',
"@": {
a: 'b',
c: 'd'
}
}
我想我会给michaelkourlas的node-js2xmlparser一个机会。
更新:现在似乎又有两个值得一提:
- chilts/data2xml
- oozcitak/xmlbuilder-js
后者是目前为止最成熟的,也是npm上下载最多的。它允许您一次性或迭代地构建XML
相关文章:
- 如何在Node.js中根据XML验证DTD
- xml文件在js项目目录结构中的位置
- Mongo-JS-如何将BSON/JSON对象转换为XML
- 通过JS/AAJAX在XML文件中搜索1个数据
- 在Drupal7中扩展字段集时,修改collapse.js以从xml获取附加数据
- Windows 8市场应用程序JS,访问远程XML文件
- 如何在 JavaScript 节点中将 xml 文件解析为数组.js
- 如何在node.js中返回与URL请求相对应的XML文件
- 带有ajax xml请求的Node js脚本不起作用
- 使用JS'更正语法;onclick'PHP echo语句中的函数与嵌入的XML获取进行AND
- 从js文件而不是xml文件创建关联数组
- 解析 XML 到 js 数据,如何访问特定标记
- 如何在 Node.js 中使用 rdflib.js 或 rdf-parser-rdfxml 解析 RDF/XML
- 在 JS 中创建、编辑和保存 XML
- XML 数据转换为 PHP 或 JS
- 使用 JS 将 XML 数据输出到 HTML
- Angular JS XML数据显示问题
- node.js xml to json objects
- JS XML解析:值不变
- 修复JS XML加载不使用async=false - how