1
我有這個XML文件:選擇元素LINQ到XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<games>
<game id="123456" name="501">
<player id="1">
<name>john</name>
<score>495</score>
<movesLeft>15</movesLeft>
<won>No</won>
<completed>uncompleted</completed>
</player>
<player id="2">
<name>
konj
</name>
<score>501</score>
<movesLeft>15</movesLeft>
<won>No</won>
<completed>uncompleted</completed>
</player>
</game>
</games>
,我創建這個查詢,但它並不能編譯:
string path = @"D:\xml\dartDatabase.xml";
XElement file = XElement.Load(path);
var query = from f in file.Element("games").Elements("game")
where (string)f.Attribute("id") == "123"
select (string)f.Element("name");
它強調的第一條線(約from
部分),說錯誤是:
'Where'not found,你是否缺少對System.Core.dll的引用或使用System.Linq的指令
怎麼了?
您是否看錯了? – SLaks 2010-12-08 23:55:22