title: How to find highest level descendants with a given name
body: <p>I am looking for a way to find the first result level in a XML tree using linq. The XML I have is like the following:</p>
  
  <pre><code>&lt;column&gt;
      &lt;row&gt;
          &lt;object/&gt;
          &lt;column column-id="1" column-name="abc"&gt;
              &lt;row&gt;
                  &lt;column&gt;
                      &lt;row&gt;
                          &lt;column column-id="2" column-name="abc"/&gt;
                      &lt;/row&gt;
                  &lt;/column&gt;
              &lt;/row&gt;
          &lt;/column&gt;
      &lt;/row&gt;
      &lt;row&gt;
          &lt;column column-id="3" column-name="abc"&gt;
              &lt;row&gt;
                  &lt;column/&gt;
              &lt;/row&gt;
          &lt;/column&gt;
      &lt;/row&gt;
  &lt;/column&gt;
  </code></pre>
  
  <p>Now I want to get all the first level <code>columns</code> where the column-name is <code>abc</code>. So the result should be:</p>
  
  <pre><code>&lt;column column-id="1" column-name="abc"&gt;...&lt;/column&gt;
  &lt;column column-id="3" column-name="abc"&gt;...&lt;/column&gt;
  </code></pre>
  
  <p>I have tried already the following code:</p>
  
  <pre><code>layout.Descendants("column")
        .Where(x =&gt; x.Attribute("column-name").Value.Equals("abc") &amp;&amp; !x.Ancestors("column").Any());
  </code></pre>
  
  <p>This works fine when the <code>XElement layout</code> being searched is not named <code>"column"</code> and is not nested inside any container elements named <code>"column"</code>.  But my <code>XElement</code> does, in fact, belong inside a document whose root element is named <code>"column"</code>, so the <code>x.Ancestors("column").Any()</code> expression wrongly filters out all matches.  I.e. the problem can be reproduced using the XML string above by initializing <code>layout</code> as follows:</p>
  
  <pre><code>var layout = XElement.Parse(xmlString);
  </code></pre>
  
  <p>I want to keep the relation in the variable because of changes I have to make later on.</p>
  
  <p>Is there maybe a way limit the ancestors selector?</p>