有以下XML来看看:的LINQ to XML查询不能
<Countries>
<country name="India">
<State name="Maharashtra" capital="Mumbai" PIN="400001"/>
<State Name="Uttar-Pradesh" capital="Lucknow" PIN="220001"/>
</country>
<country name="Sri-Lanka">
<State name="Colombo" capital="Colombo" PIN="123456"/>
<State name="Candy" capital="Jafana" PIN="654321"/>
</country>
</Countries>
当我使用
public IEnumerable<CountryData> GetData()
{
var results = from States in StockDoc.Descendants("Countries").Descendants("Country")
where (string)states.Attribute("Name") == "India"
select new CountryData
{
_State = (string)States.Element("Country").Element("State").Attribute("Name").Value,
_Capital = (string)States.Element("Country").Element("State").Attribute("Capital").Value,
_Pin= (string)States.Element("Country").Element("State").Attribute("PIN").Value
};
return results.ToList();
}
这在实施产生错误。什么是问题?另外,请定义以上声明的含义?
我想显示在dropdownbox所有国家喜欢 -
**India**
Maharashtra
Uttar-Pradesh
**Sri-Lanka**
Colombo
Candy
而且其对应的值作为资本和PIN应在标签中显示。我怎样才能做到这一点?
的问候和感谢事先
请提供错误详细信息 –
“执行错误”。意味着编译错误或运行时错误?错误信息是什么意思? – doctorlove
请寄xml请 –