title: How to read a specified xml node value using LINQ?
body: <p>I'd like to read the browser and language values from the attached xml file when I specify the VM name value. I've tried to run the below method a number of time but I keep getting errors. Can anybody please suggest a fix for my code or a better way to get what I want?
  Thnaks very much.
  J.</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;automationSettings&gt;
  
  &lt;!--VM settings on ESX Server--&gt;
  &lt;VM name="DE-2K8" language="de" powerOn="true"&gt;
      &lt;vmClients&gt;
          &lt;vmClient name="ITXP" language="it"/&gt;
      &lt;/vmClients&gt;
      &lt;guest&gt;
          &lt;browser value = "firefox"/&gt;
          &lt;language value = "de"/&gt;
      &lt;/guest&gt;
  &lt;/VM&gt;
  
  &lt;VM name="EN2008" language="en" powerOn="true"&gt;
      &lt;vmClients&gt;
          &lt;vmClient name="IT-2K8R2ENT64X" language="it"/&gt;
      &lt;/vmClients&gt;
      &lt;guest&gt;
          &lt;browser value = "chrome"/&gt;
          &lt;language value = "en"/&gt;
      &lt;/guest&gt;
  &lt;/VM&gt;
  
  &lt;/automationSettings&gt;
  </code></pre>
  
  <p>Here's the code I'm using to try to get the browser or language values:</p>
  
  <pre><code>public static string ReadVMSettings(string systemName, string section, string name)
  {
      try
      {
          systemsFilePath = @"C:\Text.xml";
          Console.WriteLine("Systems.xml path is: " + systemsFilePath);
          XDocument systemXML = XDocument.Load(systemsFilePath);
  
          var result = from vm in systemXML.Descendants("automationSettings")
                       .Descendants("VM")
                       .Descendants(section)
                       where vm.Attribute("name").Value == systemName
                       select vm.Element(name).Attribute("value").Value;
          return result.First();
      }
  
      catch (Exception ex)
      {
          Console.WriteLine("ReadVMSettings exception: " + ex.ToString());
          return string.Empty;
      }
  }
  </code></pre>
  
  <p>Call it like this:
      ReadVMSettings("EN2008", "guest", "language");</p>
  
  <p>Thnaks.</p>