特定属性选择节点我想我的LINQ语句在下面的例子只的CustomField与NAME =“必需”取与使用LINQ
<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只需要在采摘这种情况下
下面是我试过的陈述。评论在哪里不工作
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( “名”)== “必需”'是'x.Attribute( “名称”)值== “必需”'? – barrick 2014-09-02 21:19:44
我试了两种。没有运气.. – mhn 2014-09-02 21:26:40