XElement root = XElement.Load(@"c:ChinaArea.xml");
//var list = (from data in root.Elements("Province").ElementAt(1).Elements("City").ElementAt(0).Elements("Area") select data.Attribute("Name").Value.ToString()).ToList();
//string str = list.Aggregate((s1, s2) => string.Format("{0},{1}", s1, s2));
//MessageBox.Show(str);
var tianqin = from data in root.Elements("Province") where data.Attribute("Name").Value == "天津市" select data;
if (tianqin.Count() > 0)
{
var list = (from data in tianqin.Elements("City").ElementAt(0).Elements("Area") select data.Attribute("Name").Value.ToString()).ToList();
string str = list.Aggregate((s1, s2) => string.Format("{0},{1}", s1, s2));
MessageBox.Show(str);
}
else
{
MessageBox.Show("没有天津");
}
////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<Data>
<Province Name="北京市">
<City Name="北京市">
<Area Name="东城区" />
<Area Name="西城区" />
<Area Name="崇文区" />
<Area Name="宣武区" />
<Area Name="朝阳区" />
<Area Name="丰台区" />
<Area Name="石景山区" />
<Area Name="海淀区" />
<Area Name="门头沟区" />
<Area Name="房山区" />
<Area Name="通州区" />
<Area Name="顺义区" />
<Area Name="昌平区" />
<Area Name="大兴区" />
<Area Name="怀柔区" />
<Area Name="平谷区" />
<Area Name="密云县" />
<Area Name="延庆县" />
</City>
</Province>
<Province Name="澳门">
<City Name="澳门">
<Area Name="花地玛堂区" />
<Area Name="圣安多尼堂区" />
<Area Name="大堂区" />
<Area Name="望德堂区" />
<Area Name="风顺堂区" />
<Area Name="氹仔" />
<Area Name="路环" />
</City>
</Province>
</Data>