title: get dictionary from xdocument c#
body: <p>I have an xml like the following:</p>
  
  <pre><code>&lt;NewDataSet&gt;
  &lt;Person&gt;
      &lt;FirstName&gt;abc&lt;/FirstName&gt;
      &lt;LastName&gt;xyz&lt;/LastName&gt;
      &lt;Address&gt;12345abc&lt;/Address&gt;
  &lt;/Person&gt;
  &lt;Person&gt;
      &lt;FirstName&gt;abcd&lt;/FirstName&gt;
      &lt;LastName&gt;pqr_xyz&lt;/LastName&gt;
      &lt;Address&gt;1111abc&lt;/Address&gt;
  &lt;/Person&gt;
  &lt;Person&gt;
      &lt;FirstName&gt;abcde&lt;/FirstName&gt;
      &lt;LastName&gt;ghy_xyz&lt;/LastName&gt;
      &lt;Address&gt;98765abc&lt;/Address&gt;
  &lt;/Person&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>Now I want this xml into a dictionary. Following is the code I am using.</p>
  
  <pre><code> string data =
   @"&lt;NewDataSet&gt;&lt;Person&gt;...";
   XDocument doc = XDocument.Parse(data); 
   Dictionary&lt;string, string&gt; dataDictionary = new Dictionary&lt;string, string&gt;();
   foreach (XElement elem in doc.Descendants("Person"))
      {
          var row = elem.Descendants();
          string str = elem.ToString();
          foreach (XElement element in row)
          {
             string keyName = element.Name.LocalName;
             dataDictionary.Add(keyName, element.Value);
          }
          yield return dataDictionary;
      }
  </code></pre>
  
  <p>Now this code is not working. I know there is a silly mistake somewhere, can anyone please help me out?
  Here is a sample of somewhat similar requirement <a href="https://stackoverflow.com/questions/7255882/convert-xdocument-to-ienumerabledictionarystring-object">convert xdocument to IEnumerable&lt;Dictionary&lt;string, object&gt;&gt;</a>, but I can not get it to work either.</p>
  
  <p>thanks,</p>