How to count number of xml descendants for each xml element, i.e:
<Person >
<Name >Paxton</Name>
<City >Munich</City>
<Age >29</Age>
</Person>
<Person >
<Name >Mike</Name>
<City >Orlando</City>
<Age >33</Age>
I mean first Person has 7 nodes below itself, Name has 5 noes etc..
I tried using
element.Descendants().Count()
but this returns only childs unfortunately.
I believe you need
element.Elements().Count(). If element is a Person node, it will return number of person’s elements. I.e.3for your sample xml (Name, Age, City). XElement.Elements() will return only direct descendants of element. XElement.Descendants() will return all children on any level.