如何在xml文件中获取特定名称的值

时间:2017-04-05 06:30:01

标签: ruby-on-rails xml ruby-on-rails-4 xml-parsing ruby-on-rails-5.1

Traceback (most recent call last):
  File "bt.py", line 34, in <module>
    results = pool.map_async(main, range(5)).get(1e5)
  File "/opt/anaconda/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
NameError: Exception in func0

我知道像

这样的简单文件xml文件
        <ecomexpress-objects version="1.0">
        <object pk="1" model="awb">
        <field type="BigIntegerField" name="awb_number">700054480</field>
        <field type="CharField" name="orderid">5012</field>
        <field type="FloatField" name="actual_weight">0.5</field>
        <field type="CharField" name="origin">DELHI-DSW</field>
        <field type="CharField" name="destination">DELHI-DLN</field>
        <field type="CharField" name="customer">Ecom Express Private Limited - 32012</field>
        <field type="CharField" name="consignee">MUKESH KUMAR GUPTA</field>
        <field type="CharField" name="pickupdate">11-Feb-2013</field>
        <field type="CharField" name="status">Delivered / Closed</field>
        <field type="CharField" name="reason_code"/>
        <field type="CharField" name="reason_code_description"/>
        <field type="CharField" name="reason_code_number">999</field>
        <field type="CharField" name="receiver">mukesh 9999488339</field>
        <field type="CharField" name="expected_date">12-Feb-2013</field>
        <field type="CharField" name="last_update_date">05-Apr-2013</field>
        <field type="CharField" name="delivery_date">2013-02-17 11:26:00</field>
        <field type="CharField" name="ref_awb">None</field>
        <field type="CharField" name="rts_shipment"/>
        <field type="CharField" name="system_delivery_update">2013-02-17 11:26:00 </field>
        <field type="CharField" name="rts_system_delivery_status"/>
        <field name="scans">
        <object pk="1" model="scan_stages">
        <field type="DateTimeField" name="updated_on">05 Apr, 2013, 19:40 hrs</field>
        <field type="CharField" name="status">SAL Tally closed</field>
        <field type="CharField" name="reason_code"/>
        <field type="CharField" name="reason_code_number"/>
        <field type="CharField" name="location">DLN</field>
        <field type="CharField" name="Employee">Umesh Jaswanti - 10015</field>
        </object>
        <object pk="2" model="scan_stages">
        <field type="DateTimeField" name="updated_on">05 Apr, 2013, 19:39 hrs</field>
        <field type="CharField" name="status">SAL Tally closed</field>
        <field type="CharField" name="reason_code"/>
        <field type="CharField" name="reason_code_number"/>
        <field type="CharField" name="location">DLN</field>
        <field type="CharField" name="Employee">Umesh Jaswanti - 10015</field>
        </object>
        </field>
        </object>
        </ecomexpress-objects>

如何阅读并获得特定价值但在第一种情况下,我希望 status =&#39;已交付/已关闭&#39; 我怎么能得到它..

是否有任何阅读文件的教程任何获取值然后请与我分享

1 个答案:

答案 0 :(得分:1)

我认为你应该试试Nokogiri gem。