title: How to get all xml files in a directory that satisfy attribute
body: <p>I'm new to C# and I'm currently working on a side project to better my skills at it and I'm dealing with a bunch of XML data. I was wondering if there was a way to find XML files under a certain directory that satisfy certain attributes e.g. all cities that start with an I, or all phone numbers from the range 1000000000 - 1111111111. I have been looking up Linq to XML because that seems to be what a lot of people use when it comes to XML parsing in C# but I don't know what to use. Any help would be appreciated.</p>
  
  <p>My initial approach is to:
  Open each XML file in the directory and look up said attribute, and if they match move or make a copy of the XML file into a different directory, and loop until I check all the files in the directory. Hopefully there's a smarter and faster way of figuring this out? Maybe put on a list all the XML filenames that satisfy the attribute? </p>
  
  <p>Thank you!</p>
  
  <p>Edit: Sample XML Structure:</p>
  
  <pre><code>`&lt;DallasMavericks&gt;
    &lt;Players&gt;
      &lt;Name&gt;Dirk Nowitzki&lt;/Name&gt;
      &lt;Age&gt;36&lt;/Age&gt;
      &lt;Height&gt;7 foot&lt;/Height&gt;
      &lt;Weight&gt;245 lbs&lt;/Weight&gt;
      &lt;YearsPlayed&gt;16&lt;/YearsPlayed&gt;
    &lt;/Players&gt;
  &lt;/DallasMavericks&gt;`
  </code></pre>
  
  <p>and on a different XML File I could have</p>
  
  <pre><code>`&lt;SanAntonioSpurs&gt;
    &lt;Players&gt;
      &lt;Name&gt;Tim Duncan&lt;/Name&gt;
      &lt;Age&gt;38&lt;/Age&gt;
      &lt;Height&gt;6 foot 11 inches&lt;/Height&gt;
      &lt;Weight&gt;256 lbs&lt;/Weight&gt;
      &lt;YearsPlayed&gt;17&lt;/YearsPlayed&gt;
    &lt;/Players&gt;
  &lt;/SanAntonioSpurs&gt;`
  </code></pre>
  
  <p>and the idea is to search for the XML files with say players with Years Played > 15, or players who are >30 years old.</p>
  
  <p>Edit 2: I'm barely starting so this is what I'm heading towards in terms of code:</p>
  
  <pre><code>// check all xml files in the directory
  foreach (string xmlFile in Directory.EnumerateFiles(directory, "#.xml"))
  {
      // read all xml files
      string contents = File.ReadAllText(xmlFile);
  }
  
  // attribute we are using
  int age = 30;
  
  // check to see if Age attribute is greater than age 
  var query = from age in xmlFile.Root.Elements("Age")
                   where (int)age.Attribute("Age") &gt; age
                   select (int)age.Attribute("Age");
  
  var files = query.ToList();
  </code></pre>
  
  <p>Now I'm still looking to see what to do next. Any thoughts if I'm in the right direction or totally wrong?</p>