檢索節點計數xml基於條件我無法檢索具有以下屬性的節點的正確計數:IsTrue =「true」my xml。我使用根據條件使用linq
代碼是:>>>
Array depCnfg = (from node in xml.Descendants(Qualities).Descendants()
where node.Parent.Name == Qualities &&
(node.Attribute(ISTRUE).Value.ToString().ToLower() == "true")
select {
totalCount = node.Nodes().Count()}).ToArray();
XML USED: >>>
<Qualities>
<General>
<Tag1 IsTrue = "true">
<SubTag1>0</SubTag1>
</Tag1>
<Tag2 IsTrue = "false">
<SubTag2>0</SubTag2>
</Tag2>
</General>
</Qualities>
在這裏,我總是得到數爲2,但實際上它應該是1 如果任何人有一個想法,請分享...謝謝
是depCnfg.Count == 2還是defCnfg [0] .totalCount == 2? – Rich 2012-03-13 18:02:31
@Rich:'select'中的totalCount值爲2;即在xml文件中都讀取和,這是不正確的。我嘗試在Count()內使用lambda表達式,但它不起作用。 –
spins3
2012-03-13 18:55:36
您仍然用'node.Nodes()'計數所有節點,而不是'IsTrue ==「true」'的節點。 – 2012-03-14 12:34:17