title: XML parse check if attribute exist
body: <p>I've made a method which checks if an attribute exist in a XML-file. If it does not exist it returns "False". It works but it takes a very long time to parse the file. It seems it reads the whole file for each single row. Have I missed something here? Can I make it more effective somehow?</p>
  
  <pre><code>    public static IEnumerable&lt;RowData&gt; getXML(string XMLpath)
      {
          XDocument xmlDoc = XDocument.Load("spec.xml");
  
          var specs = from spec in xmlDoc.Descendants("spec")
                      select new RowData
                      {
                          number= (string)spec.Attribute("nbr"),
                          name= (string)spec.Attribute("name").Value,
                          code = (string)spec.Attribute("code").Value,
                          descr = (string)spec.Attribute("descr").Value,
                          countObject = checkXMLcount(spec),
  
  
          return specs;
      }
  
      public static string checkXMLcount(XElement x)
      {
          Console.WriteLine(x.Attribute("nbr").Value);
          Console.ReadLine();
          try
          {
              if (x.Attribute("mep_count").Value == null)
              {
                  return "False";
              }
              else
              {
                  return x.Attribute("mep_count").Value;
              }
          }
          catch
          {
              return "False";
          }
      }
  </code></pre>
  
  <p>I tested to replace the method with one that only returns and receive string:</p>
  
  <pre><code>public static string checkXMLcount(string x)
  {
      Console.WriteLine(x);
      Console.ReadLine();
      return x;
  
  }
  </code></pre>
  
  <p>I made a XML-file with only one single row. The console prints out the value 15 times.  Any ideas?</p>