title: XML Multiple Tag Issue Android
body: <p>I am working with xml and I have come across an issue that I can't get around. I have tags in the xml code that are labeled the same, and i need to pull them all in, but the code that i have at the moment is only pulling in the first tag. The xml code i am trying to parse is:</p>
  
  <pre><code>&lt;Pickup&gt;
    &lt;AddressLine&gt;Address Line 1&lt;/AddressLine&gt;
    &lt;AddressLine&gt;Address Line 2&lt;/AddressLine&gt;
    &lt;AddressLine&gt;Address Line 3&lt;/AddressLine&gt;
    &lt;AddressLine&gt;Address Line 4&lt;/AddressLine&gt;
    &lt;AddressLine&gt;Address Line 5&lt;/AddressLine&gt;
       &lt;Postcode&gt;
          &lt;PostcodeOut&gt;PostCode One&lt;/PostcodeOut&gt;
          &lt;PostcodeIn&gt;PostCode Two&lt;/PostcodeIn&gt;
       &lt;/Postcode&gt;
       &lt;AddressCoords&gt;
          &lt;Latitude&gt;00.000000&lt;/Latitude&gt;
          &lt;Longitude&gt;-0.000000&lt;/Longitude&gt;
      &lt;/AddressCoords&gt;
  </code></pre>
  
  <p></p>
  
  <p>The code i am parsing the data with is:</p>
  
  <pre><code>    XMLParser parser = new XMLParser();
      Document doc = parser.getDomElement(xml); // getting DOM
      references = new ArrayList&lt;String&gt;();
      NodeList nl = doc.getElementsByTagName("Bookings");
      NodeList nlpickup = doc.getElementsByTagName("Pickup");
      NodeList nldestination = doc.getElementsByTagName("Destination");
      NodeList nlAddress = doc.getElementsByTagName("AddressLine");
  
      AddressData = new StringBuilder();
      addressData = new ArrayList&lt;String&gt;();
  
  
      // looping through all item nodes &lt;item&gt;
      for (int i = 0; i &lt; nl.getLength(); i++) {              
  
          Element e = (Element) nl.item(i);
          resultCode = parser.getValue(e, "BookingNo");
          DateTime = parser.getValue(e, "PickupTime");
  
          Element etwo = (Element) nlpickup.item(i);
          Element eaddress = (Element) nlAddress.item(i);
          PAddressTwo = parser.getValue(eaddress, "AddressLine");
  
           AddressData.append(PAddressTwo + " ,");
  
          PPostIn = parser.getValue(etwo, "PostcodeOut");
          PPostOut = parser.getValue(etwo, "PostcodeIn");
          VType = parser.getValue(e, "VehicleType");
          Dist =parser.getValue(e, "Mileage");
  
          Element ethree = (Element) nldestination.item(i);
          DAddressOne = parser.getValue(ethree, "AddressLine");
          DPostIn = parser.getValue(ethree, "PostcodeOut");
          DPostOut = parser.getValue(ethree, "PostcodeIn");
  
      }
  </code></pre>
  
  <p>The xml parser that i am using is:</p>
  
  <pre><code>public class XMLParser {
  
  // constructor
  public XMLParser() {
  
  }
  
  /**
   * Getting XML from URL making HTTP request
   * @param url string
   * */
  public String getXmlFromUrl(String url) {
      String xml = null;
  
      try {
          // defaultHttpClient
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(url);
  
          HttpResponse httpResponse = httpClient.execute(httpPost);
          HttpEntity httpEntity = httpResponse.getEntity();
  
  
  
          xml = EntityUtils.toString(httpEntity);
          InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  is, "iso-8859-1"), 8);
          StringBuilder sbtwo = new StringBuilder();
          String myfeed = null;
          while ((myfeed = reader.readLine()) != null) {
              final String newjsontwo = myfeed.replaceAll(
                      "throw 'allowIllegalResourceCall is false.';", "");
              sbtwo.append(newjsontwo);
          }
          is.close();
  
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      // return XML
      return xml;
  }
  
  /**
   * Getting XML DOM element
   * @param XML string
   * */
  public Document getDomElement(String xml){
      Document doc = null;
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      try {
  
          DocumentBuilder db = dbf.newDocumentBuilder();
  
          InputSource is = new InputSource();
              is.setCharacterStream(new StringReader(xml));
              doc = db.parse(is); 
  
          } catch (ParserConfigurationException e) {
              Log.e("Error: ", e.getMessage());
              return null;
          } catch (SAXException e) {
              Log.e("Error: ", e.getMessage());
              return null;
          } catch (IOException e) {
              Log.e("Error: ", e.getMessage());
              return null;
          }
  
          return doc;
  }
  
  /** Getting node value
    * @param elem element
    */
   public final String getElementValue( Node elem ) {
       Node child;
       if( elem != null){
           if (elem.hasChildNodes()){
               for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
                   if( child.getNodeType() == Node.TEXT_NODE  ){
  
                       return child.getNodeValue();
                   }
               }
           }
       }
       return "";
   }
  
   /**
    * Getting node value
    * @param Element node
    * @param key string
    * */
   public String getValue(Element item, String str) {     
          NodeList n = item.getElementsByTagName(str);        
          return this.getElementValue(n.item(0));
      }
  </code></pre>
  
  <p>Any ideas how i get the  tags and where in the code am i going wrong? </p>