title: How to parse xml and get the corresponding values using Stax Iterator ?
body: <p>I would like to parse xml node using STAX Iterator API and get the values of each id node. In the below code, how do I get the corresponding value of id type=id2 or id3. How can I do this?</p>
  
  <pre><code>&lt;entity&gt;
     &lt;id type="id1"&gt;8500123&lt;/id&gt;
     &lt;id type="id2"&gt;8500124&lt;/id&gt;
     &lt;id type="id3"&gt;8500125&lt;/id&gt;
     &lt;link idType="someId"&gt;99369&lt;/link&gt;
   &lt;/entity&gt;
  </code></pre>
  
  <p>STAX Iterator API code below;</p>
  
  <pre><code>XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(new FileInputStream(fileName));
      while (xmlEventReader.hasNext()) {
          XMLEvent xmlEvent = xmlEventReader.nextEvent();
          if (xmlEvent.isStartElement()) {
              StartElement startElement = xmlEvent.asStartElement();
              if (startElement.getName().getLocalPart().equals("entity")) {
                  XMLEvent xmlEvent2 = xmlEventReader.nextEvent();//has to forgo this bcoz it always return a new line.
                  XMLEvent xmlEvent3 = xmlEventReader.nextEvent();
                  if (xmlEvent3.isStartElement()) {
                      StartElement startElement2 = xmlEvent3.asStartElement();
                      if (startElement2.getName().getLocalPart().equals("id")) {
                          connector = new Connector();
                          Attribute idAttr = startElement2.getAttributeByName(new QName("type"));
                          if(idAttr.getName().equals("id1")){
                              connector.setId1(idAttr.getValue());
                          }
                      }
                  }
              }
          }
      } 
  </code></pre>