特定屬性選擇節點我想我的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