title: Counting the element cell in a table not in the whole file. Can't find the error in my code
body: <p>My code counts cells inside a table. I can't find out why my code is counting all the cells in the file, instead of checking it table per table in the file. Below is my code.</p>
  
  <pre><code>public void CheckCellCountPerTableRow()
          {
              foreach (var table in _xdoc.Descendants("text").Descendants("table"))
              {
                  var constantcellcount = true;
                  if (!table.IsEmpty)
                  {
                      var cellcount = table.Element("row").Elements("cell").Count();
                      foreach (var row in table.Elements("row"))
                      {
                          var ctr = 0;
                          foreach (var cell in row.Elements("cell"))
                          {
                              try
                              {
                                  ctr = ctr + int.Parse(cell.Attribute("cols").Value);
                              }
                              catch (NullReferenceException nullReferenceException)
                              {
                                  ctr++;
                              }
                          }
                          if (cellcount != ctr)
                          {
                              constantcellcount = false;
                              break;
                          }
                      }
                  }
                  if (!constantcellcount)
                  {
                      var errorlist = Errorlist;
                      var errorModel = new ErrorModel
                      {
                          LineNumber = ((IXmlLineInfo) table).LineNumber,
                          ErrorMessage = "Unequal number of cell distribution in the table",
                          Text = Regex.Match(Regex.Replace(table.ToString(), @"\r\n", ""), "&lt;row&gt;.*?&lt;/row&gt;", RegexOptions.Singleline).Value.Replace(" /&gt;", "/&gt;")
                      };
                      errorlist.Add(errorModel);
                  }
              }
          }
  </code></pre>
  
  <p>Below is my xml tag.</p>
  
  <pre><code>&lt;p&gt;
      &lt;table&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell/&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell&gt;90&lt;/cell&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell cols="2"/&gt;
              &lt;cell/&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell/&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell&gt;11&lt;/cell&gt;
          &lt;/row&gt;
      &lt;/table&gt;
  &lt;/p&gt;
  &lt;p&gt;blah blah blah&lt;/p&gt;
  &lt;p&gt;
      &lt;table&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell&gt;90&lt;/cell&gt;
              &lt;cell/&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell&gt;90&lt;/cell&gt;
              &lt;cell&gt;90&lt;/cell&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell cols="3"/&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell&gt;90&lt;/cell&gt;
              &lt;cell/&gt;
          &lt;/row&gt;
          &lt;row&gt;
              &lt;cell&gt;blah&lt;/cell&gt;
              &lt;cell&gt;11&lt;/cell&gt;
              &lt;cell&gt;90&lt;/cell&gt;
          &lt;/row&gt;
      &lt;/table&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>1st table consist of 2 cell in each row, and the 2nd table consist of 3 table, this xml tag flagged as error which is not correct, the checking of cell count in every should be table per table () and not in whole file. I am wondering what is wrong with my code.</p>