111,093
社区成员




<?xml version="1.0" encoding="gb2312"?>
<Configurations version="987654" xmlns="http://www.ytlcn.com">
<SensorDefList>
<SensorDef id="1" name="红外传感器" description="" type="273" address="9a3b2451" />
<SensorDef id="2" name="门廊开关" description="门廊灯" type="258" address="9a3b2452" />
<SensorDef id="3" name="厨房卫生间开关" description="单键开关" type="258" address="9a3b2453" />
<SensorDef id="4" name="客厅开关" description="双键开关" type="260" address="9a3b2454" />
<SensorDef id="5" name="卧室床头开关" description="单键开关" type="258" address="9a3b2455" />
<SensorDef id="6" name="卧室门口开关" description="双键开关" type="260" address="9a3b2456" />
<SensorDef id="7" name="卧室阳台门窗磁" description="" type="272" address="9a3b2457" />
<SensorDef id="8" name="阳台照度传感器" description="" type="514" address="9a3b2458" />
<SensorDef id="9" name="门卡" description="" type="274" address="9a3b2459" />
<SensorDef id="10" name="关门廊灯定时器" description="" type="771" param1="3" />
<SensorDef id="11" name="温感" description="" type="1025" address="9a3b2461" />
<SensorDef id="12" name="天亮时段" description="" type="770" param1="180" param2="e3" />
<SensorDef id="13" name="傍晚时段" description="" type="770" param1="480" param2="e3" />
</SensorDefList>
</Configurations>
XDocument doc = new XDocument();
doc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "Configuration.xml");
XNamespace ns = "http://www.ytlcn.com";
List<XElement> elementList = doc.Descendants(ns + "SensorDef").ToList();
public class SensorDef
{
private String Id;
public String id
{
get { return Id; }
set { Id = value; }
}
private String Name;
public String name
{
get { return Name; }
set { Name = value; }
}
private String Description;
public String description
{
get { return Description; }
set { Description = value; }
}
private String Type;
public String type
{
get { return Type; }
set { Type = value; }
}
private String Address;
public String address
{
get { return Address; }
set { Address = value; }
}
private String ParamOne;
public String paramOne
{
get { return ParamOne; }
set { ParamOne = value; }
}
private String ParamTwo;
public String paramTwo
{
get { return ParamTwo; }
set { ParamTwo = value; }
}
}
var god = from xl in elementList
select new SensorDef
{
id = xl.Attribute("id").Value,
name = xl.Attribute("name").Value,
description = xl.Attribute("description").Value,
type = xl.Attribute("type").Value,
address = xl.Attribute("address").Value,
paramOne = xl.Attribute("param1").Value,
paramTwo = xl.Attribute("param2").Value,
};
List<SensorDef> sensorList = (List<SensorDef>)god;
XNamespace ns = "http://www.ytlcn.com";
IEnumerable<XElement> elementList = doc.Descendants(ns + "SensorDef");
var god = from xl in elementList
select new SensorDef
{
id = xl.Attribute("id").Value,
name = xl.Attribute("name").Value,
description = xl.Attribute("description").Value,
type = xl.Attribute("type").Value,
address = xl.Attribute("address") == null ? "" : xl.Attribute("address").Value,
paramOne = xl.Attribute("param1") == null ? "" : xl.Attribute("param1").Value,
paramTwo = xl.Attribute("param2") == null ? "" : xl.Attribute("param2").Value
};
List<SensorDef> sensorList = god.ToList<SensorDef>();
MessageBox.Show(sensorList.Count.ToString());