Count the leaves of an XML string with C#
.net, c#, xml
Solution
XDocument xDoc = XDocument.Parse(xml);
var count = xDoc.Descendants().Where(n => !n.Elements().Any()).Count();
or as @sixlettervariables suggested
var count = xDoc.Descendants().Count(e => !e.HasElements);
Problem
Is there a simple way to get the number of all leaves of an XML string (XML document is provided as a string) with C#?