how to construct xml structure

ok,xml has a complex structure,but we also can said xml has a simple structure.so ,the importance  thing is how to design.like a this example:

<DocumentElement>

<MTU_NUM>1</MTU_NUM>         
<mtuid>5910001</mtuid>
<mtuname>参考名称</mtuname>
<area>设备所属地市</area>
<env>安装的场景</env>
<inuse>0</inuse>
<sim_info simcard_capa=”3”>            
<sim_card>
<imsi>460029731032920</imsi>
<msisdn>1385910000</msisdn>
</sim_card>
<sim_card>
<imsi></imsi>
<msisdn></msisdn>
</sim_card>
<sim_card>
<imsi>460029731032921</imsi>
<msisdn>1385910001</msisdn>
</sim_card>
</sim_info>
<coordinate>
<lon>120.0001</lon>
<lat>60.0002</lat>
</coordinate>
<sensor_info num_of_sensor=”8”>                   
<sensor_name>传感器1名称</sensor_name>
<sensor_name></sensor_name>
<sensor_name>传感器3名称</sensor_name>
<sensor_name>传感器4名称</sensor_name>
<sensor_name></sensor_name>
<sensor_name></sensor_name>
<sensor_name></sensor_name>
<sensor_name>传感器8名称</sensor_name>
</sensor_info>
<test_type_capa>                
         <MOS_UL />               
         <MOS_DL />               
<test_type_capa>
<firm_ware>
<version>01.10</version>
</firm_ware>
</DocumentElement>

how to analyse this code?frist of all ,we should know how much section  this code can be devide . this code has two type label.xmlroot is </DocumentElement>,this contain some xmlelement,and some element has their own xmlelement and xmlattribute. 

<sensor_info num_of_sensor=”8”>                   
<sensor_name>传感器1名称</sensor_name>
<sensor_name></sensor_name>
<sensor_name>传感器3名称</sensor_name>
<sensor_name>传感器4名称</sensor_name>
<sensor_name></sensor_name>
<sensor_name></sensor_name>
<sensor_name></sensor_name>
<sensor_name>传感器8名称</sensor_name>
</sensor_info>
num_of_sensor is xmlattribute and   sensor_name is xmlelement.
how to describe this layer?i think  class is a good method. <DocumentElement> is a class ,and he contain many attribute,some of this is xmlelement,and another is xmlattribute.this attribute may be is just attribute,may be a class contain their own xmlattribute and xmlelement. like <sensor_info>,code just like this:
public class at
{
      [xmlelement("sensor_name")]
      public string mtuid;
 
      [xmlelement("sensor_name")]
      public string mtuname;
      [xmlelement("sensor_name")]
     public sensor_name newSensorName = new sensor_name;
............................................
}
 
public class sensor_name
{
      [xmlattribute("num_of_sensor")]
      public string  num_of_sensor;
 
      [xmlelement("sensor_name")]
      public list<string> sensorName = new list<string>();
}
so ,we can deal with  all type xml structure,and can use method to searlize it.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值