关闭

how to construct xml structure

374人阅读 评论(0) 收藏 举报

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.  
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9634次
    • 积分:236
    • 等级:
    • 排名:千里之外
    • 原创:13篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类