title: navigate through XML document with XMLpullParser
body: <p>I am using the <code>XmlPullParser</code> to pull data from an <strong>XML</strong> document.  My <strong>XML</strong> document is structured like this:</p>
  
  <pre><code>&lt;creature id="1"&gt;
  &lt;name&gt;CreatureName&lt;/name&gt;
  &lt;type&gt;CreatureType&lt;/type&gt;
  &lt;size&gt;CreatureSize&lt;/size&gt;
  &lt;/creature&gt;
  &lt;creature id="2"&gt;
  &lt;name&gt;CreatureName&lt;/name&gt;
  &lt;type&gt;CreatureType&lt;/type&gt;
  &lt;size&gt;CreatureSize&lt;/size&gt;
  &lt;/creature&gt;
  &lt;creature id="3"&gt;
  &lt;name&gt;CreatureName&lt;/name&gt;
  &lt;type&gt;CreatureType&lt;/type&gt;
  &lt;size&gt;CreatureSize&lt;/size&gt;
  &lt;/creature&gt;
  </code></pre>
  
  <p>My code is currently working if I only have one creature in my <strong>XML</strong> file.  </p>
  
  <p>I'm looking for a way to chose the creature based on the creature ID.  For example, if the ID was 2, then the <code>XMLPullParser</code> would only parse the <strong>XML</strong> under creature ID="2".</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>xpp.next();
  String elName = "";
  int encounterId = 0; 
  int eventType = xpp.getEventType();
  
  while (eventType != XmlPullParser.END_DOCUMENT)
      {
  
   if(eventType == XmlPullParser.START_DOCUMENT)
   {      
       System.out.println("START_DOCUMENT "+xpp.getName());
   }
   else if(eventType == XmlPullParser.START_TAG)
   {
       if(encounterId &gt;= 0) {
           if(xpp.getName().equalsIgnoreCase("creature")) {
               System.out.println("inside while loop --- "+xpp.getName());
               try {
                   encounterId = Integer.parseInt(xpp.getAttributeValue(0));
                   System.out.println("attribute value = " + encounterId);
               } catch (NumberFormatException e) {
                   Log.e("attribute value error", e.getMessage());
               }
               //DETERMINE ELEMENT NAME
           } else if(xpp.getName().equalsIgnoreCase("name")) {
               System.out.println("inside while loop --- "+xpp.getName());
               elName = "name";
           } else if(xpp.getName().equalsIgnoreCase("type")) {
               elName = xpp.getName();
               elName = "type";
           } else if(xpp.getName().equalsIgnoreCase("size")) {
               elName = xpp.getName();
           elname = "size";
               }
  
   } else if(eventType == XmlPullParser.END_TAG) {
       System.out.println("End tag "+xpp.getName());
  
   } else if(eventType == XmlPullParser.TEXT) {
       //COLLECT DATA
  
       if(elName.equalsIgnoreCase("name")) {
          this.name = xpp.getText();
       } else if(elName.equalsIgnoreCase("type"))  {
          this.race = xpp.getText();
       } else if(elName.equalsIgnoreCase("size")) {
          this.gender = xpp.getText(); 
   }
  eventType = xpp.next();
  }    
  </code></pre>
  
  <p>Thanks!</p>