I have this XML file:
<?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>
<开发者_如何学Python/game>
</games>
and I create this query, but it does not compile:
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");
It underlines the first line (around from
section), saying the error is:
'Where' not found, are you missing a reference to System.Core.dll or using directive for System.Linq
What's wrong?
Add using System.Linq;
精彩评论