我无法填充XML文件中的对象。我已经复制了一个我几乎完全找到的示例,并更改了变量名称,但是我一直收到“枚举未找到结果”异常。LINQ to XML。枚举没有结果
这是我的代码:
Dim element As XElement = XElement.Load(path)
Dim itemProps = From p In element...<Property> _
Where p.<LanguageCode>.Value = "en_us" _
Select p.<Title>.Value, p.<Description>.Value
使用断点,我已经证实,“元素”变量是使用XElement.Load(path)方法被正确填充。
这里是正在访问的XML文件:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Items>
<Item ItemID="1">
<Property ItemPropertyID="1">
<Title>Title1</Title>
<Description>Description1</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="2">
<Property ItemPropertyID="2">
<Title>Title2</Title>
<Description>Description2</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="3">
<Property ItemPropertyID="3">
<Title>Title3</Title>
<Description>Description3</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="4">
<Property ItemPropertyID="4">
<Title>Title4</Title>
<Description>Description4</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="5">
<Property ItemPropertyID="5">
<Title>Title5</Title>
<Description>Description5</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="6">
<Property ItemPropertyID="6">
<Title>Title6</Title>
<Description>Description6</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
</Items>
本质上来说,XML查询应该返回标题,并且具有所谓的语言代码元素的每个属性的说明,这等于到“en-us”。我有一种感觉,我的问题在于我的XML代码,但我现在已经陷入了很长时间。请帮忙。
+1,但你不配作弊SO:P – alf
哇,我不敢相信我错过了那个。 – user961794
Holy C ** p我也不能......我没有看到那个人...... *拍拍自己* :-) – shawty