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.  
阅读更多
个人分类: C#
上一篇something about XmlSerializer
下一篇something about deal with string
想对作者说点什么? 我来说一句

Soa And Webservices.pdf

2010年07月29日 3.64MB 下载

hierarchy_construction.pdf

2013年04月09日 951KB 下载

Gecho DOM Reference[chm]

2008年03月22日 383KB 下载

没有更多推荐了,返回首页

关闭
关闭