Javascript 什么';s是节点JS的最佳JSON或JS对象到XML转换模块
我需要从JS对象构建一个相对简单的XML文档,其中包含一些层次结构和一些属性。在选择其中一个模块之前,我现在站在这里:Javascript 什么';s是节点JS的最佳JSON或JS对象到XML转换模块,javascript,xml,json,node.js,Javascript,Xml,Json,Node.js,我需要从JS对象构建一个相对简单的XML文档,其中包含一些层次结构和一些属性。在选择其中一个模块之前,我现在站在这里: 我应该选择哪个模块 这个问题可能会被认为不是一个好问题,但我不知道如何提出不同的问题 免责声明:我在每个存储库上发布了与问题相同的问题 这是我要构建的XML: <?xml version="1.0" encoding="UTF-8"?> <orders> <order> <order_orderid&
<?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>
123123
345345
7604
qwert
0
国标
02
0
qwerty
Q.W.E
Qwerty
某公司
邮政汽车
13
1234 AB
那里
NL
a@b.nl
0168-123456
06-12345678
1234
8765432
164-05-366
2.
一些礼券
1233
5678
8765432
164-05-367
3.
其他礼券
1244
我调查了自己
| 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 |
然后是需要比较的对象类型
:
:
看起来很复杂
:
我想我会给michaelkourlas的node-js2xmlparser一次机会
更新:现在似乎还有两个值得一提:
后者是迄今为止最成熟的,并在npm上下载。它允许您一次性或迭代地构建XML。如果它很简单,并且给出了密钥名称,为什么不自己动手呢?如果您没有任何特殊要求,请选择最小的一个。如果它对您有效,请尝试一下,然后对此感到满意。@adeneo因为最好重用具有更多贡献者并且也受其他项目依赖的代码。我不应该重新发明轮子。即使是简单的东西,因为需求总是在以后增加。好吧,这取决于你,我只会写一些适合我需要的东西。如果你看一下列出的模块,它们都非常简单,这只是一个递归循环,将JSON中的键和值放入XML标记中。@ChristiaanWesterbeek你错了。除非你提供更多关于你的具体案例的信息,否则我是adeneo的。谢谢你的帖子。我还发现有趣的是,看看哪些模块(大多数)被阻塞,哪些模块实际使用回调来回调结果。关于这一点的任何意见现在都被弃用,取而代之的是
xmlbuilder2
。
{
"_name": 'foo',
"_content": 'bar',
"_attrs": {
"a": 'b',
"c": 'd'
}
}
items: [{
"name": 'one',
"_id": 1
}, {
"name": 'two',
"_id": 2
}
]
foo: {
"#": 'bar',
"@": {
a: 'b',
c: 'd'
}
}