【发布时间】:2012-09-18 17:26:57
【问题描述】:
我在进行 API 调用时返回了以下 XML。我需要为每个<order_status>、<payment_status> 和<fulfillment_status> 创建一个包含<status> 和<description> 值的数组。谁能分享一些对我有帮助的知识?
<orderwave>
<call_result>
<order>
<order_number>17377</order_number>
<orderwave_order_number>RWD-336475921</orderwave_order_number>
<order_status>
<status>active</status>
<description>This order is free to be charged and shipped. It is open in the orderwave workflow.</description>
</order_status>
<payment_status>
<status>declined</status>
<description>This order has been declined by the payment network.</description>
</payment_status>
<fulfillment_status>
<status>not shipped</status>
<description>This order has not been allocated for shipment.</description>
</fulfillment_status>
</order>
</call_result>
<warning_count>0</warning_count>
<warnings/>
<error_count>0</error_count>
<errors/>
</orderwave>
【问题讨论】:
-
存储在这个数组中的对象的类型是什么?您是想简单地将 XML 分解为更小的 XDocument,还是想要一种更强类型的方法?
-
你应该使用 linqToXML
-
看看使用
List<T>,T是一个对象来保存你想要的数据,然后使用 LINQ to XML 将文档解析到列表中。如果以后有时间,我会发布一个示例。