u84six
u84six

Reputation: 4941

How to get a count of every single element in an xml file using linq to xml?

I've tried a bunch of queries using two xml files; one is the copy of the other. After removing a child of a child in one doc, I still get the same count when getting all elements. Can someone give an example of getting every single element in an xml file (siblings, children, etc) and returning the count? I just want to know how many elements are in the file. I don't need to filter or get values.

Upvotes: 0

Views: 86

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

The simplest way:

var xDoc = XDocument.Load(yourDocumentPath);
var nbOfElements = xDoc.Descendants().Count();

Upvotes: 6

Related Questions