【发布时间】:2014-08-10 03:27:26
【问题描述】:
我需要构建一个相对简单的 XML 文档,其中包含一些来自 JS 对象的层次结构和一些属性。我现在站在选择以下模块之一之前:
- 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>
【问题讨论】:
-
如果它很简单并且给出了键名,为什么不自己做呢?
-
IMO 如果您没有任何特殊要求,请选择最小的。尝试它是否适合您,然后对此感到满意。
-
@adeneo 因为最好重用有更多贡献者并且也被其他项目依赖的代码。我不应该重新发明轮子。即使是简单的东西,因为需求总是在以后增加。
-
好吧,这取决于你,我会写一些适合我需要的东西。如果您查看列出的模块,它们都非常简单,这只是一个递归循环,将 JSON 中的键和值放入 XML 标记中。
-
@ChristiaanWesterbeek 你错了。除非您提供有关您的具体案例的更多信息,否则我支持 adeneo。
标签: javascript xml json node.js