使用第三方框架Xstream轻松解析xml数据

前端之家收集整理的这篇文章主要介绍了使用第三方框架Xstream轻松解析xml数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近项目中由于特殊原因服务器返回的数据是xml格式的数据,由于数据量比较大,xml类型比较复杂,用传统的办法封装的工具类来解析着实蛋疼。于是寻找第三方的解析框架发现有如下几个:

综合对比之后发现还是XStream最符合我的需求,于是记录方便以后使用。本文只讲XStream,至于其他可以自行研究。

1.Android Studio引入XStream添加依赖:

compile 'com.thoughtworks.xstream:xstream:1.4.8'
2.这个是项目里面的XML数据够复杂吧。
<?xml version="1.0" encoding="utf-8"?>

<joblist> 
  <!--警告清单通知内容清单-->  
  <interfacelist interface="warnlist"></interfacelist>  
  <!--如果手动选了下一步骤工序,且工序有多条记录需要选择其中一条记录-->  
  <interfacelist interface="nextstep"> 
    <next_step> 
      <rkey>374</rkey>  
      <step_number>2</step_number>  
      <dept_code>PPPRE</dept_code>
      <!--下一步工作组-->  
      <next_group_list>
        <next_group> 
          <rkey>586</rkey>  
          <dept_code>PPPRE_G1</dept_code>  
          <dept_name>半固化片开料工作组1</dept_name>
        </next_group>
        <next_group> 
          <rkey>587</rkey>  
          <dept_code>PPPRE_G2</dept_code>  
          <dept_name>半固化片开料外发组1</dept_name>
        </next_group>
      </next_group_list>
    </next_step> 
  </interfacelist>  
  <!--产出工作中心-->  
  <interfacelist interface="outcenter"> 
    <out_list> 
      <rkey>473</rkey>  
      <dept_code>CUPRE_W1</dept_code>  
      <dept_name>铜箔开料工作中心1</dept_name> 
    </out_list> 
  </interfacelist>  
  <!--作业单在制品行记录信息-->  
  <interfacelist interface="worknumberinfor"> 
    <work_order_number>170502002-0-46-01</work_order_number>  
    <dept_code>CUPRE_G1铜箔开料工作组1</dept_code>  
    <dept_name>铜箔开料工作组1</dept_name>  
    <d0034_rkey>471</d0034_rkey>  
    <parts_per_panel>16</parts_per_panel>  
    <parts_per_set>4</parts_per_set>  
    <manu_part_number>01-04</manu_part_number>  
    <customer_part_number>DC12834</customer_part_number>  
    <cp_rev>C3</cp_rev>  
    <whouse_ptr>2</whouse_ptr>  
    <wo_datecode></wo_datecode>  
    <quan_sch>960</quan_sch>  
    <quan_rej>0</quan_rej>  
    <rkey>196890</rkey>  
    <step>1</step>  
    <qty_backlog>960</qty_backlog>  
    <panels>60</panels>  
    <to_be_stocked1>0</to_be_stocked1>  
    <sets_qty>240</sets_qty> 
  </interfacelist>  
  <!--控制开关清单-->  
  <interfacelist interface="controlinfor"> 
    <!--控制开关行索引-->  
    <power_index>0</power_index>  
    <!--是否允许修改接板数量-->  
    <permit_split_lot>1</permit_split_lot>  
    <!--是否允许修改接收工序-->  
    <changeacceptdept>1</changeacceptdept>  
    <!--是否需要录入周码-->  
    <datecode_entry_flag>False</datecode_entry_flag>  
    <!--录入周码需要遵照的字段格式-->  
    <datecode_entry_flagformat>/</datecode_entry_flagformat>  
    <!--是否需要入仓处理-->  
    <stock_entry_flag>0</stock_entry_flag>  
    <!--默认仓库-->  
    <stock_rkey_default>14</stock_rkey_default>  
    <stock_code_default>ST005</stock_code_default>  
    <stock_name_default>产成品仓库</stock_name_default>  
    <stock_place_default>P0001</stock_place_default> 
  </interfacelist>  
  <!--仓库清单-->  
  <interfacelist interface="stocklist"> 
    <stock_list> 
      <rkey>14</rkey>  
      <code>ST005</code>  
      <name>产成品仓库</name>  
      <place_list> 
        <list> 
          <rkey>3</rkey>  
          <code>P0001</code>  
          <name>货架一</name> 
        </list>  
        <list> 
          <rkey>4</rkey>  
          <code>P0002</code>  
          <name>货架二</name> 
        </list>  
        <list> 
          <rkey>5</rkey>  
          <code>P0003</code>  
          <name>货架三</name> 
        </list> 
      </place_list> 
    </stock_list>  
    <stock_list> 
      <rkey>16</rkey>  
      <code>ST007</code>  
      <name>成品退货仓库</name>  
      <place_list> 
        <list> 
          <rkey>8</rkey>  
          <code>X01</code>  
          <name></name> 
        </list>  
        <list> 
          <rkey>9</rkey>  
          <code>X02</code>  
          <name></name> 
        </list> 
      </place_list> 
    </stock_list>  
    <stock_list> 
      <rkey>25</rkey>  
      <code>ST014</code>  
      <name>全程外协成品库</name>  
      <place_list></place_list> 
    </stock_list>  
    <stock_list> 
      <rkey>27</rkey>  
      <code>ST016</code>  
      <name>外包仓库</name>  
      <place_list></place_list> 
    </stock_list>  
    <stock_list> 
      <rkey>28</rkey>  
      <code>ST017</code>  
      <name>虚拟全程外协成品库</name>  
      <place_list></place_list> 
    </stock_list>  
    <stock_list> 
      <rkey>29</rkey>  
      <code>ST018</code>  
      <name>暂停发货仓库</name>  
      <place_list></place_list> 
    </stock_list>  
    <stock_list> 
      <rkey>33</rkey>  
      <code>ST020</code>  
      <name>成品包装仓</name>  
      <place_list></place_list> 
    </stock_list> 
  </interfacelist>  
  <!--使用工具清单-->  
  <interfacelist interface="toollist"></interfacelist>  
  <!--子部件分配-->  
  <interfacelist interface="innerpartlist"> 
    <innerpart_list> 
      <cut_no>170502002-0</cut_no>  
      <wo_ptr>204292</wo_ptr>  
      <d38_ptr>691386</d38_ptr>  
      <bom_ptr>29072</bom_ptr>  
      <bom_step>1</bom_step>  
      <manu_part_number>02-03</manu_part_number>  
      <qty_bom>1</qty_bom>  
      <sumneed_bom>960</sumneed_bom>  
      <need_bom>0</need_bom>  
      <pcs_issued>960</pcs_issued>  
      <pnl_issued>120</pnl_issued>  
      <set_issued>298</set_issued> 
    </innerpart_list>  
    <innerpart_list> 
      <cut_no>170502002-0</cut_no>  
      <wo_ptr>204292</wo_ptr>  
      <d38_ptr>691386</d38_ptr>  
      <bom_ptr>29071</bom_ptr>  
      <bom_step>1</bom_step>  
      <manu_part_number>钻P片</manu_part_number>  
      <qty_bom>1</qty_bom>  
      <sumneed_bom>960</sumneed_bom>  
      <need_bom>960</need_bom>  
      <pcs_issued>0</pcs_issued>  
      <pnl_issued>0</pnl_issued>  
      <set_issued>0</set_issued> 
    </innerpart_list> 
  </interfacelist>  
  <!--自制品分配-->  
  <interfacelist interface="selfpartlist"> 
    <selfpart_list> 
      <cut_no>170502002-0</cut_no>  
      <wo_ptr>204292</wo_ptr>  
      <d38_ptr>691386</d38_ptr>  
      <whouse_ptr>2</whouse_ptr>  
      <bom_rkey50>8666</bom_rkey50>  
      <bom_step>1</bom_step>  
      <manu_part_number>AC07574A0</manu_part_number>  
      <qty_bom>1</qty_bom>  
      <sumneed_bom>960</sumneed_bom>  
      <need_bom>0</need_bom>  
      <quan_issued>960</quan_issued>  
      <quan_on_hand>117197</quan_on_hand> 
    </selfpart_list>  
    <selfpart_list> 
      <cut_no>170502002-0</cut_no>  
      <wo_ptr>204292</wo_ptr>  
      <d38_ptr>691386</d38_ptr>  
      <whouse_ptr>2</whouse_ptr>  
      <bom_rkey50>16669</bom_rkey50>  
      <bom_step>1</bom_step>  
      <manu_part_number>003S0002</manu_part_number>  
      <qty_bom>1</qty_bom>  
      <sumneed_bom>960</sumneed_bom>  
      <need_bom>0</need_bom>  
      <quan_issued>960</quan_issued>  
      <quan_on_hand>0</quan_on_hand> 
    </selfpart_list> 
  </interfacelist> 
</joblist>
原文链接:https://www.f2er.com/xml/293495.html

猜你在找的XML相关文章