 <p>You could do something like this, but I would think long about actually putting it into production code.</p> <pre><code>from n in testData.Elements("test_data") .Aggregate(new Dictionary&lt;string, TreeNode&lt;string&gt;&gt;() {{ string.Empty, new TreeNode&lt;string&gt;() }}, (d, e) =&gt; { var curNode = new TreeNode&lt;string&gt;(e.Element("ID").Value); d.Add(e.Element("Title").Value, curNode); d[e.Element("child_of").Value].AddChild(curNode); return d; }) .Values where n.Parent == null select n; </code></pre> <p>Note that this assumes that an element has a parent key of "empty string" or comes in the source list after its parent.</p> <p>Personally, I would factor this (especially the aggregation) into a method of its own.</p>