I came upon this situation where I wanted to know the count of a certain node in an XML file. Now the count of that node could be way more than 50k so there was no way it could have been counted manually.
Therefore, I used LINQ to XML to get the count of the node.
The code for the same is as below:
- string filename = @"C:\Vipul\Desktop\test.xml";
- var count = XDocument.Load(filename).Root.Descendants("ThisNode").Count();
- Console.WriteLine(count);
This count of the node "ThisNode" is now in the variable count and can be used as required.
In case of any queries, please feel free to comment.