title: Can I speed up my code for downloading XML pages?
body: <p>I have a program that needs to download ~200 XML pages of ~250 lines. It does this by grabbing a list of ID's from a main page, and then it then iterates through each ID, inserting it into a URL and using a StreamWriter to write the XML page to a file. The methods look like this:</p>
  
  <pre><code>    private static void XMLUpdate(string path)
      {
          try
          {
              //create client for downloading XMLs
              var client = new WebClient();
  
              foreach (var node in GetId())
              {
                  //stores xml text into a string
                  var s = client.DownloadString("https://example" + node + "/xml");
  
                  // assign to the output
                  var file = new StreamWriter(path + "\\" + node + ".xml");
                  file.WriteLine(s);
                  file.Close();
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
  
      private static string[] GetId()
      {
          var idList = new List&lt;string&gt;();
          var request = WebRequest.Create("https://example/xml");
  
          var i = 0;
  
          using (var response = request.GetResponse())
          using (var xmlReader = XmlReader.Create(response.GetResponseStream()))
          {
              while (xmlReader.Read())
              {
                  xmlReader.ReadToFollowing("n" + i);
                  //go through each of the n nodes in the xmldocument and get the name and id
                  if (xmlReader.NodeType != XmlNodeType.Element || xmlReader.Name != "n" + i) continue;
                  xmlReader.ReadToFollowing("id");
  
                  if (xmlReader.NodeType == XmlNodeType.Element &amp;&amp; xmlReader.Name == "id")
                  {
                      var id = xmlReader.ReadElementContentAsString();
                      idList.Add(id);
                  }
  
                  i += 1;
              }
          }
  
          var IDs = idList.ToArray();
  
          return IDs;
      }
  </code></pre>
  
  <p>At the moment the program takes a long time to download everything I need. Is there something I can do to speed up the process?</p>