title: Downloading only first item from web service - Android
body: <p>I want to download items from a web service to Android app (Web service output - XML). I'm using Android Download Manager class for downloading part.  </p>
  
  <p>When I click download button  , it only downloads the first item from XML list. This is what I tried. Help me to download all files. </p>
  
  <pre><code>  try {
          URL url = new URL("http://localhost/WebService/gettext.aspx? ");       
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document doc = db.parse(new InputSource(url.openStream()));
          doc.getDocumentElement().normalize();
  
          doc.getDocumentElement().normalize();
  
          NodeList nodeList = doc.getElementsByTagName("image");
  
          iname = new TextView[nodeList.getLength()];
          itime = new TextView[nodeList.getLength()];
          int listlength = nodeList.getLength();
          for (int i = 0; i &lt; nodeList.getLength(); i++) {
  
              Node node = nodeList.item(i);
  
              itime[i] = new TextView(this);
              iname[i] = new TextView(this);
  
              Element fstElmnt = (Element) node;
              NodeList nameList = fstElmnt.getElementsByTagName("iname");
              Element nameElement = (Element) nameList.item(0);
              nameList = nameElement.getChildNodes();
              iname[i].setText(((Node) nameList.item(0)).getNodeValue());
  
              NodeList itimeList = fstElmnt.getElementsByTagName("itime");
              Element websiteElement = (Element) itimeList.item(0);
              itimeList = websiteElement.getChildNodes();
              itime[i].setText("ITime = "
                      + ((Node) itimeList.item(0)).getNodeValue());
  
              imgName=iname[i].getText().toString().trim();
  //Image folder.
                  dwnload_file_path = "http://localhost/WebService/Images/"+URLEncoder.encode(iname[i].getText().toString(),"UTF-8");
  
              String servicestring = Context.DOWNLOAD_SERVICE;
  
              downloadmanager = (DownloadManager) getSystemService(servicestring);
  
  
              Uri uri = Uri.parse(dwnload_file_path);
              DownloadManager.Request request = new DownloadManager.Request(uri);
  
  
               request.setDestinationInExternalPublicDir("/Download",imgName.toString());
  
              downloadId = downloadmanager.enqueue(request);
  
  
          }
      } catch (Exception e) {
          System.out.println("EEEEEEEEE "+ e.toString());
          //Toast.makeText(getBaseContext(),"35",Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p>This is the XML output from web service.</p>
  
  <pre><code>&lt;!-- language: xml --&gt;
  &lt;image&gt;
  &lt;iname&gt;abdf.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;bcdf.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;cd.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;efe.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;ggef.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;hiefef.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;mmfer.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;nnnef.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;iname&gt;erer.jpg&lt;/iname&gt;
  &lt;itime&gt;10000&lt;/itime&gt;
  &lt;/image&gt;
  </code></pre>