title: Check if an element exists in XML
body: <p>XML:</p>
  
  <pre><code>&lt;CONFIGURATION&gt;
  &lt;Files&gt;
      &lt;File&gt;D:\Test\TestFolder\TestFolder1\TestFile.txt&lt;/File&gt;
      &lt;File&gt;D:\Test\TestFolder\TestFolder1\TestFile01.txt&lt;/File&gt;
      &lt;File&gt;D:\Test\TestFolder\TestFolder1\TestFile02.txt&lt;/File&gt;
      &lt;File&gt;D:\Test\TestFolder\TestFolder1\TestFile03.txt&lt;/File&gt;
      &lt;File&gt;D:\Test\TestFolder\TestFolder1\TestFile04.txt&lt;/File&gt;
  &lt;/Files&gt;
  &lt;SizeMB&gt;3&lt;/SizeMB&gt;
  &lt;BackupLocation&gt;D:\Log backups\File backups&lt;/BackupLocation&gt;
  &lt;/CONFIGURATION&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>private void btnLinq_Click(object sender, EventArgs e)
      {
          queryData(@"D:\WatchMe1\backupconfig1.xml");
      }
  
  static void queryData(string xmlFile)
      {
          var xdoc = XDocument.Load(xmlFile);
          var configuration = xdoc.Element("CONFIGURATION");
          string sizeMB = configuration.Element("SizeMB").Value;
          string backupLocation = configuration.Element("BackupLocation").Value;
          //need a code here to check if element &lt;File&gt; exist before executing the file array
          string[] files = configuration.Element("Files").Elements("File").Select(c =&gt; c.Value).ToArray();
  
          foreach (string file in files)
          {
              Console.WriteLine(file);
          }
      }
  </code></pre>
  
  <p>I have an xml writer program that edits the above xml. The Files element can be changed to Folder element. I have another program that reads the values(file locations) and do something with it, I have to check first if the element is a Files or Folders element.</p>