title: How to add items to a dictionary from a linq query?
body: <p>I'm trying to check an xml file for nodes <code>disp-formula</code> which has a attribute "<strong>id</strong>" and the attribute contains values like <code>deqnX-Y</code> where both <code>X</code> and <code>Y</code> are integers and if match found then add them in the below manner in a dictionary</p>
  
  <pre><code>Key                             Value
  "rid="deqnX""               "rid="deqnX-Y""
  "rid="deqnX+1""             "rid="deqnX-Y""
  ...  ...
  "rid="deqnY""               "rid="deqnX-Y""
  
  incrementing value of X by 1 till it reaches Y
  </code></pre>
  
  <p>I've tried the below code but got stuck middle way and I can't figure out what to do.</p>
  
  <pre><code> Dictionary&lt;string, string&gt; dict = new Dictionary&lt;string, string&gt;();
  
              XDocument doc = XDocument.Load(@"D:\Practice\test.xml",LoadOptions.PreserveWhitespace);
              var x =from y in doc.Descendants("disp-formula")
                     where y.Attribute("id").Value.Contains(@"deqn(\d+)-(\d+)")
                     select y.Attribute("id");
              foreach (var item in x)
              {
  
                  dict.Add(item);
              }
  </code></pre>
  
  <p>Here is a sample xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;article article-type="research"&gt;
  &lt;front&gt;
  &lt;journal-meta&gt;
  &lt;issn pub-type="paper"&gt;0327-286X&lt;/issn&gt;
  &lt;publisher&gt;
  &lt;publisher-name&gt;IEEE&lt;/publisher-name&gt;
  &lt;/publisher&gt;
  &lt;/journal-meta&gt;
  &lt;article-meta&gt;
  &lt;article-id pub-id-type="doi"&gt;10.1245/11.202136&lt;/article-id&gt;
  &lt;title-group&gt;
  &lt;article-title&gt;Dragon Ball Super popularity in USA&lt;/article-title&gt;
  &lt;/title-group&gt;
  &lt;/article-meta&gt;
  &lt;/front&gt;
  &lt;body&gt;
  &lt;sec id="S1"&gt;
  &lt;label&gt;1.&lt;/label&gt;
  &lt;p&gt;....
  &lt;disp-formula id="deqn1"&gt;
  ...
  &lt;/disp-formula&gt;
  &lt;/p&gt;
  &lt;/sec&gt;
  &lt;sec id="S2"&gt;
  &lt;label&gt;2.&lt;/label&gt;
  &lt;p&gt;...
  &lt;disp-formula id="deqn2-6"&gt;
  ...
  &lt;/disp-formula&gt;&lt;/p&gt;
  &lt;p&gt;...
  &lt;disp-formula id="deqn7"&gt;
  ...
  &lt;/disp-formula&gt;
  &lt;/p&gt;
  &lt;p&gt;&lt;disp-formula id="deqn8-10"&gt;
  ...
  &lt;/disp-formula&gt;&lt;/p&gt;
  &lt;/sec&gt;
  &lt;/body&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>This should be the dictionary items after running the program</p>
  
  <pre><code>Key                             Value
  "rid="deqn2""               "rid=""deqn2-6""
  "rid="deqn3""               "rid=""deqn2-6""
  "rid="deqn4""               "rid=""deqn2-6""
  "rid="deqn5""               "rid=""deqn2-6""
  "rid="deqn6""               "rid=""deqn2-6""
  "rid="deqn8""               "rid=""deqn8-10""
  "rid="deqn9""               "rid=""deqn8-10""
  "rid="deqn10""              "rid=""deqn8-10""
  </code></pre>