I am unable to retrieve correct count of the nodes with attribute: IsTrue = “true” of my xml.
Code that I am using is :>>>
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>
Here I always get the count as 2 but actually it should be 1.
If anyone have an idea please share…Thanks
You can use the following LINQ query to get the count. This is grabbing the ‘Qualities’ node and putting it into it’s own element. Then we are looking at each descendant, and check the following:
Then it gets the count of the elements that meet that criteria. This is assuming there is only one ‘Qualities’ node. In that case you would have to use XElement qualities = element.Element*s*(“Qualities”); .