title: Conditional LINQ query on XML file
body: <p>I would appreciate some help on a LINQ query I am doing on an XML file.  I haven't been able to find anything in my searches that apply in my case but I have to admit I am still trying to figure out LINQ.  So, i apologize in advance if this is is a repeat and I overlooked something.</p>
  
  <p>I have an XML file that is created and filled at the time of the application starting.  I am searching this XML file and trying to list all the "Connection" elements found under "Citrix" for a given hostname only.</p>
  
  <p>So, for example, given the below XML file, I would want to only return<br>
  "desktop3" and "desktop4" if "client2" is selected.</p>
  
  <p>Example of XML file:</p>
  
  <pre><code>&lt;ThinClients&gt;
    &lt;ThinClient&gt;
      &lt;Status&gt;OK&lt;/Status&gt;
      &lt;Hostname&gt;client1&lt;/Hostname&gt;
      &lt;Citrix&gt;
        &lt;Connection&gt;
          &lt;ConnectionName&gt;desktop1&lt;/ConnectionName&gt;
          &lt;XendesktopIP&gt;192.168.0.10&lt;/XendesktopIP&gt;
        &lt;/Connection&gt;
        &lt;Connection&gt;
          &lt;ConnectionName&gt;desktop2&lt;/ConnectionName&gt;
          &lt;XendesktopIP&gt;192.168.0.20&lt;/XendesktopIP&gt;
        &lt;/Connection&gt;
      &lt;/Citrix&gt;
    &lt;ThinClient&gt;
    &lt;ThinClient&gt;
      &lt;Status&gt;OK&lt;/Status&gt;
      &lt;Hostname&gt;client2&lt;/Hostname&gt;
      &lt;Citrix&gt;
        &lt;Connection&gt;
          &lt;ConnectionName&gt;desktop3&lt;/ConnectionName&gt;
          &lt;XendesktopIP&gt;192.168.0.30&lt;/XendesktopIP&gt;
        &lt;/Connection&gt;
        &lt;Connection&gt;
          &lt;ConnectionName&gt;desktop4&lt;/ConnectionName&gt;
          &lt;XendesktopIP&gt;192.168.0.40&lt;/XendesktopIP&gt;
        &lt;/Connection&gt;
      &lt;/Citrix&gt;
    &lt;ThinClient&gt;
  &lt;ThinClients&gt;
  </code></pre>
  
  <p>I am able to get a list of all Citrix connections on all ThinClients, but I am struggling on getting just ones for a specified hostname.</p>
  
  <p>The following returns all the Citrix connections for all hosts, but I am failing to understand how to take it further and only isolate it to hostname since the hostname is further up the XML chain.</p>
  
  <pre><code>public ObservableCollection&lt;CitrixConnections&gt; GetCitrixConnectionListByHostname(string Hostname)
  {
  IEnumerable&lt;CitrixConnections&gt; clients =
      (from client in _Document.Elements("ThinClient").Elements("Citrix").Elements("Connection")
       select new CitrixConnections
       {
           ConnectionName = client.Element("ConnectionName").Value,
           XendesktopIP = client.Element("XendesktopIP").Value,
       });
  
  var clientsAsObservableCollection = new ObservableCollection&lt;CitrixConnections&gt;(clients);
  return clientsAsObservableCollection;
  }
  </code></pre>