title: JAXB Unmarshalling XML string - Looping through all tags
body: <p>I am new to Java programming and I am doing Unmarshalling the following XML string. My task is get the names of the customers in 
  this string. I have done it for one customer. I need to get all the customer names. I need help on the looping part. This works for one customer</p>
  
  <p>My Java code:</p>
  
  <pre><code>      XMLInputFactory xif = XMLInputFactory.newFactory();
        Reader reader = new StringReader(response.toString());
        XMLStreamReader xsr = xif.createXMLStreamReader(reader);
        while(xsr.hasNext()) {
        if(xsr.isStartElement() &amp;&amp; xsr.getLocalName().equals("customer")) {
               break;
           }
            xsr.next();
       }
  
       JAXBContext jc = JAXBContext.newInstance(Customer.class);
       Unmarshaller unmarshaller = jc.createUnmarshaller();
       JAXBElement&lt;Customer&gt; jb = unmarshaller.unmarshal(xsr,Customer.class);
  
        Customer customer = jb.getValue(); 
       System.out.println(customer.NAME);
  </code></pre>
  
  <p>Customer Class:</p>
  
  <pre><code>@XmlRootElement(name = "customer")
  public class Customer {
  
  public String NAME;
  
    public String getNAME ()
      {
         return NAME;
      }
  
  }
  </code></pre>
  
  <p>Data Class:</p>
  
  <pre><code> @XmlRootElement(namespace = "data")
   public class Data
   {
   @XmlElementWrapper(name = "data")
    // XmlElement sets the name of the entities
    @XmlElement(name = "customer")
    {
     private Customer[] customer;
     public Customer[] getCustomer ()
     {
       return customer;
   }
  
  
  &lt;data&gt;
  &lt;customer&gt;
  &lt;name&gt;ABC&lt;/name&gt;
  &lt;city&gt;DEF&lt;/city&gt;
  &lt;/customer&gt;
  &lt;customer&gt;
  &lt;name&gt;ABC&lt;/name&gt;
  &lt;city&gt;DEF&lt;/city&gt;
  &lt;/customer&gt;
  &lt;customer&gt;
  &lt;name&gt;ABC&lt;/name&gt;
  &lt;city&gt;DEF&lt;/city&gt;
  &lt;/customer&gt;
  &lt;/data&gt;
  </code></pre>