I am trying to switch from XmlDocument to Linq, and am struggling to get what I want.
I have XML similar to this,
<root>
<Surfer Status='5'>
<Name>Billy</Name>
<County>Cornwall</County>
</Surfer>
<Surfer Status='5'>
<Name>Tim</Name>
<County>Cornwall</County>
</Surfer>
<Surfer Status='10'>
<Name>Ryan</Name>
<County>Devon</County>
</Surfer>
</root>
I can count all the surfers like this.
XDocument X = XDocument.Load("Surfers.xml");
int Total = X.Descendants("Surfer").Count();
I was hoping to count all the Surfers with a Status of 5 like this
int fives = X.Descendants["Surfer[@Status='5']").Count();
but it doesn't work!
it doesn't work? Are you getting an error message ? Or are you simply not getting the expected result ?