Question: I am working on a C# code. I have my XML document with with different nodes, Out of which I need to count the number of nodes having the same innertext value. I am Using XmlDocument. Let's say I have a xml file where I have to count the number of nodes having InnerText value BSS.

Code:

```
<Annotations>
 <Objects>
  <ObjectId>BSS</ObjectId>
  <ObjectId>CAT</ObjectId>
 </Objects>
<Objects>
  <ObjectId>BSS</ObjectId>
  <ObjectId>ABC</ObjectId>
 </Objects>
<Objects>
  <ObjectId>BSS</ObjectId>
  <ObjectId>PCT</ObjectId>
 </Objects>
</Annotations>

```

Here in the Above code I want to count the number of nodes having innertext value BSS.like here the count should be 3.Your help will be greatly appreciated.

Edited Code:

```
<Annotations>
 <Objects>
  <ObjectId>BSS|SAF|PAT</ObjectId>
  <ObjectId>CAT</ObjectId>
 </Objects>
<Objects>
  <ObjectId>BSS|SAF|PAT</ObjectId>
  <ObjectId>ABC</ObjectId>
 </Objects>
<Objects>
  <ObjectId>BSS|SAF|PAT</ObjectId>
  <ObjectId>PCT</ObjectId>
 </Objects>
</Annotations>

```

Answer: 
I would use the new `Linq to XML` api instead :

```
var xDocument = XDocument.Load("path");

int count = xDocument.Descendants().Count(x => (string)x == "BSS");

```
```
XmlDocument xmlD = new XmlDocument();
xmlD.Load(Server.MapPath("sample.xml"));
XmlNodeList xmlNL = xmlD.GetElementsByTagName("tagName");
xmlNL.Count;

```