我無法填充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