【发布时间】:2014-09-03 06:01:21
【问题描述】:
我希望我的 Linq 语句仅获取以下示例中具有 name="Required" 的自定义字段
<root>
<appinfo>
<application app_id=1234 app_name="SomeName">
<customfield name="Required" value="123" />
<customfield name="Not Required" value="234" />
<customfield name="Not Required" value="345" />
<customfield name="Not Required" value="456" />
<customfield name="Not Required" value="678" />
</application>
</appinfo>
...
</root>
1234,SomeName,123在这种情况下需要选择
以下是我尝试过的陈述。评论的 Where 不起作用
var appAI =
from appinfo in doc.Root.Elements()
let application = appinfo.Elements().First()
let custom_field = application.Descendants()
//.Where(x => (string)x.Attribute("name") == "Required" && (string)x.Attribute("value").Value !="" )
select new
{
app_id = (string)application.Attribute("app_id"),
app_name = (string)application.Attribute("app_name"),
app_AI = custom_field
};
【问题讨论】:
-
不应该是
x.Attribute("name") == "Required"是x.Attribute("name").Value == "Required"? -
我都试过了。没有运气..