title: how is read/parsing xml java STAX (mechanism)
body: <p>I try to understand how is working the mechanism of STAX java.</p>
  
  <p>I have this xml file </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;orders&gt;
      &lt;order created='2012-07-12T15:29:33.000' ID='2343'&gt;
          &lt;product&gt;
              &lt;description&gt;Sony 54.6" (Diag) Xbr Hx929 Internet Tv&lt;/description&gt;
              &lt;gtin&gt;00027242816657&lt;/gtin&gt;
              &lt;price currency="USD"&gt;2999.99&lt;/price&gt;
              &lt;supplier&gt;Sony&lt;/supplier&gt;
          &lt;/product&gt;
          &lt;product&gt;
              &lt;description&gt;Apple iPad 2 with Wi-Fi 16GB - iOS 5 - Black&lt;/description&gt;
              &lt;gtin&gt;00885909464517&lt;/gtin&gt;
              &lt;price currency="USD"&gt;399.0&lt;/price&gt;
              &lt;supplier&gt;Apple&lt;/supplier&gt;
          &lt;/product&gt;
          &lt;product&gt;
              &lt;description&gt;Sony NWZ-E464 8GB E Series Walkman Video MP3 Player Blue&lt;/description&gt;
              &lt;gtin&gt;00027242831438&lt;/gtin&gt;
              &lt;price currency="USD"&gt;91.99&lt;/price&gt;
              &lt;supplier&gt;Sony&lt;/supplier&gt;
          &lt;/product&gt;
      &lt;/order&gt;
      &lt;order created='2012-07-13T16:02:22.000' ID='2344'&gt;
          &lt;product&gt;
              &lt;description&gt;Apple MacBook Air A 11.6" Mac OS X v10.7 Lion MacBook&lt;/description&gt;
              &lt;gtin&gt;00885909464043&lt;/gtin&gt;
              &lt;price currency="USD"&gt;1149.0&lt;/price&gt;
              &lt;supplier&gt;Apple&lt;/supplier&gt;
          &lt;/product&gt;
          &lt;product&gt;
              &lt;description&gt;Panasonic TC-L47E50 47" Smart TV Viera E50 Series LED HDTV&lt;/description&gt;
              &lt;gtin&gt;00885170076471&lt;/gtin&gt;
              &lt;price currency="USD"&gt;999.99&lt;/price&gt;
              &lt;supplier&gt;Panasonic&lt;/supplier&gt;
          &lt;/product&gt;
      &lt;/order&gt;
  &lt;/orders&gt;
  </code></pre>
  
  <p>To mimic the behavior of this XML file we created an object with similar attributes</p>
  
  <pre><code>public class Product {
  
      private int orderID;
      private String createTime;
      private String description;
      private String gtin;
      private String price;
      private String supplier;
  //getter and setter
  }
  </code></pre>
  
  <p>With this I tried to read my xml file:</p>
  
  <pre><code>if (xmlEvent.isStartElement()){
                 StartElement startElement = xmlEvent.asStartElement();
                 if(startElement.getName().getLocalPart().equals("order")){
                     prod = new Product();
                     Attribute idAttr = startElement.getAttributeByName(new QName("ID"));
                     if(idAttr != null){
                         prod.setgetOrderID(Integer.parseInt(idAttr.getValue()));
                     }
  
                     Attribute orderTime = startElement.getAttributeByName(new QName("created"));
                     if(orderTime != null){
                         prod.setgetCreateTime(orderTime.getValue());
                     }
  
  
  
  
                     counter++;
                     //System.out.println("Obiect creat");
                   System.out.println(counter);
                 }
                 //set the other varibles from xml elements
                 else if(startElement.getName().getLocalPart().equals("description")){
                     xmlEvent = xmlEventReader.nextEvent();
                     prod.setDescription(xmlEvent.asCharacters().getData());
  
                 }else if(startElement.getName().getLocalPart().equals("gtin")){
                     xmlEvent = xmlEventReader.nextEvent();
                     prod.setGtin(xmlEvent.asCharacters().getData());
  
                 }else if(startElement.getName().getLocalPart().equals("price")){
                     xmlEvent = xmlEventReader.nextEvent();
                     prod.setPrice(xmlEvent.asCharacters().getData());
                 }else if(startElement.getName().getLocalPart().equals("supplier")){
                     xmlEvent = xmlEventReader.nextEvent();
                     prod.setSupplier(xmlEvent.asCharacters().getData());
  
                 }
  </code></pre>
  
  <p>My problem is that, they are 5 products, but when I try to output them, are not the correct number.
   1. If in:  if(startElement.getName().getLocalPart().equals("orders"))  the last parameter is "oders" in the output i see just one object (Panasonic TC-L47E50 47" Smart TV Viera E50 Series LED HDTV)</p>
  
  <ol start="2">
  <li>If last parameter is <strong>order</strong> in my output are 2 objects</li>
  <li>if last parameter is "product" in my output I have all of them, 5.</li>
  </ol>
  
  <p>What modification i need to do, for read entire information. My scope is to read the attribute  "created"  and "id" of order but with all my objects, not 1 or 2
   Thanks !</p>