Is there an easy way to get the number of all sheets of an XML string (XML document is provided as a string) using C #?
XDocument xDoc = XDocument.Parse(xml); var count = xDoc.Descendants().Where(n => !n.Elements().Any()).Count();
or as suggested by @sixlettervariables
var count = xDoc.Descendants().Count(e => !e.HasElements);
Here's how to do it with XPath (borrow from helio):
XmlDocument doc = new XmlDocument(); doc.LoadXml("..."); int count = doc.SelectNodes("//*[not(*)]").Count;
//
*
[]
not(*)