Reputation: 331
I want to count how many childs are contained inside the HomeTeam element.This number is dynamic. I use this ,but gives me how many times HomeTeam is shown.gives me 1
int cout = xmlDoc.Descendants("HomeTeam").Count();
my XML :
<HomeStats>
<HomeTeam>
<HomeTeamName>PAN</HomeTeamName>
<IPERIOD>74</IPERIOD>
<IIPERIOD>102</IIPERIOD>
<IIIPERIOD>124</IIIPERIOD>
</HomeTeam>
</HomeStats>
the answer in this example is:The HomeTeam element contains 4 (HomeTeamName,IPERIOD,IIPERIOD,IIIPERIOD).So I must get 4. Any suggestion?
Upvotes: 0
Views: 71
Reputation: 19496
You're close. You just need to add one more step; get the child elements:
int cout = xmlDoc.Element("HomeTeam").Elements().Count();
Upvotes: 3