我的類:讀取XML用的XDocument
public class Device
{
int ID;
string Name;
List<Function> Functions;
}
和類功能:
public class Function
{
int Number;
string Name;
}
,我有這種結構的XML文件:
<Devices>
<Device Number="58" Name="Default Device" >
<Functions>
<Function Number="1" Name="Default func" />
<Function Number="2" Name="Default func2" />
<Function Number="..." Name="...." />
</Functions>
</Device>
</Devices>
這裏是代碼,其中我試圖閱讀對象:
var list = from tmp in document.Element("Devices").Elements("Device")
select new Device()
{
ID = Convert.ToInt32(tmp.Attribute("Number").Value),
Name = tmp.Attribute("Name").Value,
//??????
};
DevicesList.AddRange(list);
我怎麼能讀「功能」 ???
隨着你的'Devices'做的一樣嗎? – Schaliasos 2012-08-06 18:15:08