title: Run time XML creation in c# and saving the data
body: <p>Trying to create dynamic XML file and save the data to it, however i am able to save the last entry and not all the entries. Any thoughts?</p>
  
  <p>To generate XML file with needed nodes:</p>
  
  <h2>GenerateXML()</h2>
  
  <pre><code>            XmlDocument doc = new XmlDocument();
              XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
              doc.AppendChild(docNode);
  
              XmlNode albums = doc.CreateElement("albums");
              doc.AppendChild(albums);
  
              XmlNode album = doc.CreateElement("album");
              albums.AppendChild(album);
  
              XmlNode title = doc.CreateElement("title");
              albums.AppendChild(title);
  
              doc.Save(System.Windows.Forms.Application.StartupPath + "\\albums.xml");
  </code></pre>
  
  <p>The output from button click gives me either 10 records or 100 records or some number of records:</p>
  
  <pre><code> //album is a class returned by web service
  if (Elements.Count &gt; 0)
                  {
  
               string path = System.Windows.Forms.Application.StartupPath + "\\albums.xml";
                  //Read the file stream in read mode
                  FileStream READER = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
  
                  System.Xml.XmlDocument albumSpecs = new System.Xml.XmlDocument();
                  albumSpecs.Load(READER);
  
                  FileStream WRITER = null; 
  
                  GenerateXML();
  
                  //Create a FileStream for writing
                  WRITER = new FileStream(path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
  
  
                  XmlElement root = doc.DocumentElement;
                  XmlNodeList nodes = root.SelectNodes("//albums");
                  for (int i = 0; i &lt; ResultsList.Items.Count - 1; i++)
                  {
                      album = (Album)ResultsList.Items[i]; 
                      foreach (XmlNode node in nodes)
                      {
                          node["title"].InnerText = album.Title;
  
                      }
  
                  }
                  //Write the data to the filestream
                  doc.Save(WRITER);
              }
  </code></pre>
  
  <p>I get the last entry data in the XML and not all the entries returned.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;albums&gt;
    &lt;album /&gt;
    &lt;title&gt;She will be loved&lt;/title&gt;
  &lt;/albums&gt;
  </code></pre>
  
  <p>How do i build run time XML based on the # of entries returned?</p>