title: XML parsing using XMLReader and foreach
body: <p>I want to parse the following XML file which comes in as a String input. </p>
  
  <pre><code> &lt;leadtools_form_processing_fields&gt;
         &lt;pages&gt;
            &lt;page number="1" dpix="300" dpiy="300"&gt;
               &lt;fields&gt;
                  &lt;field type="Leadtools.Forms.Processing.TextFormField, Leadtools.Forms.Processing&gt;
                     &lt;values&gt;
                        &lt;value name="LastName" /&gt;
                        &lt;value bounds="232, 875, 736, 76 Pixel" /&gt;
                        &lt;value dropOut="None" /&gt;
                        &lt;value regex_pattern="" /&gt;
                        &lt;value ocr_text_type="FlowText" /&gt;
                        &lt;value enable_icr="False" /&gt;
                        &lt;value enable_ocr="True" /&gt;
                        &lt;value text_field_type="Character" /&gt;
                     &lt;/values&gt;
                  &lt;/field&gt;
                  &lt;field type="Leadtools.Forms.Processing.TextFormField, Leadtools.Forms.Processing&gt;
                     &lt;values&gt;
                        &lt;value name="MiddleName" /&gt;
                        &lt;value bounds="1112, 875, 475, 76 Pixel" /&gt;
                        &lt;value dropOut="None" /&gt;
                        &lt;value regex_pattern="" /&gt;
                        &lt;value ocr_text_type="FlowText" /&gt;
                        &lt;value enable_icr="False" /&gt;
                        &lt;value enable_ocr="True" /&gt;
                        &lt;value text_field_type="Character" /&gt;
                     &lt;/values&gt;
                  &lt;/field&gt;
              &lt;/fields&gt;
          &lt;/page&gt;
       &lt;/pages&gt;
  &lt;/leadtools_form_processing_fields&gt;
  </code></pre>
  
  <p>I guess XMLReader provides much efficiency than XMLDocument. How do get the values of elements in 'values' element and parse other elements using XMLReader and foreach.</p>
  
  <p>I tried this: (Kind of pseudocode)</p>
  
  <pre><code>using (XmlReader reader = XmlReader.Create(xmlData))
              {
                  while (reader.Read())
                  {
                      reader.ReadToFollowing("pages");
  
                      foreach (XmlElement Page in Pages)
                      {
                          pageNumber = Page.GetAttribute("number");
  
                          reader.ReadToFollowing("fields");
                          foreach (XmlElement field in fields)
                          {   
                              type = Page.GetAttribute("type");
                              reader.ReadToFollowing("values");
  
                              foreach (XmlElement value in values)
                              {
                                  name = value.GetAttribute("name");
                                  string bounds = value.GetAttribute("bounds");
                                  string boundValues[] = bounds.Split(,);
                                  x = boundValues[0];
                                  y = boundValues[1];
                                  width = boundValues[2];
                                  height = boundValues[3];
  
                              }
                              formFields.Add(new FormField() { Name = name, X = x, Y = y, Width = width, Height = height, PageNumber = pageNumber, FormFieldType = type });
  
                          }
  
  
                      }
  </code></pre>
  
  <p>Thank you! </p>