I am wondering if it is possible to count the number of elements in an XML document preferably being able to fitler using something similar to where (string)query.Attribute("attName") == att
.
Using the best of my knowledge i have tried the following but unfortunatly i can't seem to make it work.
var listElements = reader.Elements("shortlist");
foreach (var element in listElements)
{
XElement _xml;
location.Position = 0;
System.IO.StreamReader file = new System.IO.StreamReader(location);
_xml = XElement.Parse(file.ReadToEnd());
XAttribute attName = _xml.Attribute("attN");
if (attName.Value == att)
{
Count++;
}
}
Thanks!
Given that doc is an instance of XDocument
doc.Root.Descendants().Count(d => (string)d.Attribute("attName") == "value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With