使用 LinQ 过滤 XML 数据
我正在开发一个 Windows Phone 7 应用程序。
我有一个表中的 ID 列表,我想过滤一个包含这些表的所有信息的 XML 文件。
我有以下 C# 代码:
var filteredData =
from c in loadedData.Descendants("gameDescription")
where c.Attribute("gameType").Value == gameType &&
c.Attribute("language").Value.Equals(language)
select new SampleData.GamesDesc()
{
Id = uint.Parse(c.Attribute("game_id").Value),
. . .
};
如果我有一个 List
。我想归档结果,获取每个未从 unfinishedGamesId 获得 Id 的游戏。比如:
c.Attribute("game_id").Value != unfinishedGamesId[0] &&
c.Attribute("game_id").Value != unfinishedGamesId[1] &&
...
我怎样才能将其添加到 where 子句中?
I'm developing a Windows Phone 7 app.
I have a list of Ids from a table and I want to filter a XML file that has all information about these table.
I have the following C# code:
var filteredData =
from c in loadedData.Descendants("gameDescription")
where c.Attribute("gameType").Value == gameType &&
c.Attribute("language").Value.Equals(language)
select new SampleData.GamesDesc()
{
Id = uint.Parse(c.Attribute("game_id").Value),
. . .
};
If I have a List<long> unfinishedGamesId
. I want to filer results getting every game that hasn't got an Id from unfinishedGamesId. Something like:
c.Attribute("game_id").Value != unfinishedGamesId[0] &&
c.Attribute("game_id").Value != unfinishedGamesId[1] &&
...
How can I add this to where clause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想做什么?如果您想要包含其值在该列表中的数据,则查询将是:
假设 Id 值是您使用
uint.Parse
获得的值,则此代码应该有效:属性查找和解析两次不是很有效,但我不知道如何解决这个问题。
What are you trying to do? If you're wanting to include data whose values are in that list, the query would be:
Assuming the Id value is the one you're getting with
uint.Parse
, this code should work:Doing the attribute lookup and parse twice is not very efficient, but I'm not sure how to fix that.