I think my XML parser is clunky
<p>I have the following bit of code that reads data from an XML file.  I've been working on it for quite a while now, and after finally getting it to work, I am wondering if this is the best way to do this.  </p>

<p>Just looking at the code and it looks clunky and cumbersome.  But it does work.</p>

<p>Am I doing this all wrong?</p>

<p>Thanks</p>

<pre><code>public void getEncounterStats(Activity activity, int id)
throws XmlPullParserException, IOException
{
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.encounters);
xpp.next();
String elName = "";
//encounterID is the ID of the encounter
int encounterID = id;
//attribID is the attribute ID in the XML file
int attribID = 0;
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{

 if(eventType == XmlPullParser.START_DOCUMENT)
 {      

 }
 else if(eventType == XmlPullParser.START_TAG)
 {
     if(encounterID &gt;= 0) {
         if(xpp.getName().equalsIgnoreCase("creature")) {
             System.out.println("inside while loop --- "+xpp.getName());
             try {
                 attribID = Integer.parseInt(xpp.getAttributeValue(0));
             } catch (NumberFormatException e) {
                 Log.e("attribute value error", e.getMessage());
             }
             //DETERMINE ELEMENT NAME and set elName
         } else if(xpp.getName().equalsIgnoreCase("name")) {
             System.out.println("inside while loop --- "+xpp.getName());
             elName = "name";
         } else if(xpp.getName().equalsIgnoreCase("race")) {
             elName = xpp.getName();
         } else if(xpp.getName().equalsIgnoreCase("gender")) {
             elName = xpp.getName();
         } else if(xpp.getName().equalsIgnoreCase("alignment")) {
             elName = xpp.getName();
         } else if(xpp.getName().equalsIgnoreCase("age")) {
             elName = xpp.getName();
         } else if(xpp.getName().equalsIgnoreCase("condition")){
             elName = xpp.getName();
         } else if(xpp.getName().equalsIgnoreCase("item1")) {
             elName = xpp.getName();
         } else if(xpp.getName().equalsIgnoreCase("item2")) {
             elName = xpp.getName();
         }
     }
 } else if(eventType == XmlPullParser.END_TAG) {
     //end tag
 }  else if(eventType == XmlPullParser.TEXT) {
     //COLLECT DATA
     //check to make sure the attribID == the encounterID...will only pull data from correct ID
     if (attribID == encounterID) {
         if(elName.equalsIgnoreCase("name")) {
            setName(xpp.getText());
            System.out.println("name is  " + this.name);
         } else if(elName.equalsIgnoreCase("race"))  {
            setRace(xpp.getText());
         } else if(elName.equalsIgnoreCase("gender")) {
            setGender(xpp.getText()); 
         } else if(elName.equalsIgnoreCase("age")) {
             try {
                 setAge(Integer.parseInt(xpp.getText()));
             } catch (NumberFormatException e) {
                 Log.e("encounter.age error", e.getMessage());
             }
         } else if(elName.equalsIgnoreCase("alignment")) {
             setAlignment(xpp.getText());
         } else if(elName.equalsIgnoreCase("condition")) {
             setCondition(xpp.getText());
         } else if(elName.equalsIgnoreCase("item1")) {
             setItem1(xpp.getText());
         } else if(elName.equalsIgnoreCase("item2")) {
             setItem2(xpp.getText());
         } else {
             System.out.println("Nothing here "+xpp.getName());
         }
     }
 }
 eventType = xpp.next();

}     


}
</code></pre>
