title: LINQ to XML (C#) Iterate through nodes to build string?
body: <p>I'll cut straight to the chase!</p>
  
  <p>Here's my XML, it contains a folder structure and a list of files with their md5 hashes.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;dir name="Root"&gt;
    &lt;dir name="Folder01"&gt;
      &lt;dir name="SubFolder01"&gt;
        &lt;file md5="77c34f94b0827a2a511b7c9113fd8e31" name="file01.lua" /&gt;
        &lt;file md5="47e656c824a3de6fd6bdf7429045b570" name="file02.lua" /&gt;
        &lt;file md5="8c9d3b467fbb3173bebed99bae400995" name="file03.lua" /&gt;
        &lt;file md5="ade88ad29426e49c9a81e923bb428445" name="file04.lua" /&gt;
      &lt;/dir&gt;
      &lt;dir name="SubFolder02"&gt;
        &lt;dir name="SubFolder03"&gt;
          &lt;dir name="SubFolder04"&gt;
            &lt;file md5="e1a8566380b2a4256e1792b48705058c" name="file.png" /&gt;
          &lt;/dir&gt;
        &lt;/dir&gt;
      &lt;/dir&gt;
    &lt;/dir&gt;
    &lt;dir name="Folder02"&gt;
      &lt;dir name="SubFolder01"&gt;
        &lt;file md5="12f6a2a9e85817fdf6f791f1b0fe37b3" name="File01.lua" /&gt;
      &lt;/dir&gt;
    &lt;/dir&gt;
  &lt;/dir&gt;
  </code></pre>
  
  <p>I would like to read in this XML and generate a list of files with their md5's like this...</p>
  
  <pre><code>Root\Folder01\SubFolder01\file01.lua, 77c34f94b0827a2a511b7c9113fd8e31
  Root\Folder01\SubFolder01\file02.lua, 47e656c824a3de6fd6bdf7429045b570
  Root\Folder01\SubFolder01\file03.lua, 8c9d3b467fbb3173bebed99bae400995
  Root\Folder01\SubFolder01\file04.lua, ade88ad29426e49c9a81e923bb428445
  Root\Folder01\SubFolder02\SubFolder03\SubFolder04\file.png, e1a8566380b2a4256e1792b48705058c
  Root\Folder02\SubFolder01\File01.lua, 12f6a2a9e85817fdf6f791f1b0fe37b3
  </code></pre>
  
  <p>This is the (broken) code I have so far</p>
  
  <pre><code>var SingleFiles = SourceXMLFile.Descendants("dir")
  
                 .Select(x =&gt; new
                 {
                     FileName = (string)x.Attribute("name"),
                     md5 = (string)x.Attribute("md5")
                 });
  </code></pre>
  
  <p>I realise I neeed to iterate through the nodes and descendants to build the Filename string based on parents etc. but I'm a little burnt out at the moment (having tried numerous ways!) if anyone could help I'd be extremely grateful.</p>
  
  <p><strong>UPDATE</strong>: While the answer given by Ron.B.I. may not have actually been an answer, it did give me a push in the right direction to figure it out myself.</p>
  
  <pre><code>XmlReader rdr = XmlReader.Create(new System.IO.StringReader(XMLasString));
              string newPath = "";
              while (rdr.Read())
              {
                  if (rdr.NodeType == XmlNodeType.Element)
                  {
                      if (rdr.LocalName == "file")
                          Console.WriteLine(newPath + rdr.GetAttribute(1) + " " + rdr.GetAttribute(0));
                      else
                          newPath = newPath + (rdr.GetAttribute(0)) + Path.DirectorySeparatorChar;
                  }
              }
  </code></pre>
  
  <p>I'm going to go through the other answers now and mark the 'best' one. Thanks for all your help.</p>