title: Parse local XML File with XMLPullParser in Android
body: <p>This is what I want to do. I wrote a class which should handle my XML File. </p>
  
  <pre><code>    package de.lies;
  
      import java.io.IOException;
  
      import org.xmlpull.v1.XmlPullParser;
      import org.xmlpull.v1.XmlPullParserException;
  
      public class Entry {
      private static final String ns = null;
  
      public final String rank;
      public final String source; 
      public final String date;
      public final String headline;
      public final String description;
      public final String articleURL;
      public final String sourceURL;
      public final String imageURL;
  
      private Entry(String rank, String source, String date, String headline, String description, String articleURL, String sourceURL, String imageURL){
          this.rank           = rank;
          this.source         = source;
          this.date           = date;
          this.headline       = headline;
          this.description    = description;
          this.articleURL     = articleURL;
          this.sourceURL      = sourceURL;
          this.imageURL       = imageURL;
      }
  
      private Entry readEntry (XmlPullParser parser) throws XmlPullParserException, IOException{
          parser.require(XmlPullParser.START_TAG, ns, "entry");
          String rank         = null;
          String source       = null;
          String date         = null;
          String headline     = null;
          String description  = null;
          String articleURL   = null;
          String sourceURL    = null;
          String imageURL     = null;
  
          while(parser.next() != XmlPullParser.END_TAG) {
              if(parser.getEventType() != XmlPullParser.START_TAG){
                  continue;
              }
              String name     = parser.getName();
  
              if(name.equals("rank")){
                  rank        = readRank(parser);
              } else if(name.equals("source")){
                  source      = readSource(parser);
              } else if(name.equals("date")){
                  date        = readDate(parser);
              } else if(name.equals("headline")){
                  headline    = readHeadline(parser);
              } else if(name.equals("description")){
                  description = readDescription(parser);
              } else if(name.equals("articleURL")){
                  articleURL  = readArticleURL(parser);
              } else if(name.equals("sourceURL")){
                  sourceURL   = readSourceURL(parser);
              } else if(name.equals("imageURL")){
                  imageURL    = readImageURL(parser);
              } else {
                  skip(parser);
              }
          }
          return new Entry(rank, source, date, headline, description, articleURL, sourceURL, imageURL);
      }
  
      private String readRank(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String rank         = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return rank;
      }
  
      private String readSource(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "source");
          String source       = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "source");
          return source;
      }
  
      private String readDate(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String date         = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return date;
      }
  
      private String readHeadline(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String headline     = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return headline;
      }
  
      private String readDescription(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String description      = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return description;
      }
  
      private String readArticleURL(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String articleURL       = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return articleURL;
      }
  
      private String readSourceURL(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String sourceURL        = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return sourceURL;
      }
  
      private String readImageURL(XmlPullParser parser) throws IOException, XmlPullParserException{
          parser.require(XmlPullParser.START_TAG, ns, "rank");
          String imageURL     = readText(parser);
  
          parser.require(XmlPullParser.END_TAG, ns, "rank");
          return imageURL;
      }
  
      private String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
          String result = "";
  
          if (parser.next() == XmlPullParser.TEXT) {
              result = parser.getText();
              parser.nextTag();
          }
          return result;
      }
  
  
      private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
          if (parser.getEventType() != XmlPullParser.START_TAG) {
              throw new IllegalStateException();
          }
          int depth = 1;
          while (depth != 0) {
              switch (parser.next()) {
              case XmlPullParser.END_TAG:
                  depth--;
                  break;
              case XmlPullParser.START_TAG:
                  depth++;
                  break;
              }
          }
       }
  }
  </code></pre>
  
  <p>The problem I have now is how to handle the XML File. In particular: How to read in the XML-File and how to let the class do the work for the file and print it out to the Android Device. Would appreciate any help. To be more precise I have an XML file that has this layout</p>
  
  <pre><code>&lt;entry&gt;
  &lt;rank&gt;Rank 1&lt;/rank&gt;
      &lt;source&gt;&lt;![CDATA[Der Postillon]]&gt;&lt;/source&gt;
      &lt;date&gt;2013-09-24 15:11:48&lt;/date&gt;
      &lt;scores&gt;
          &lt;Flies&gt;10797&lt;/Flies&gt;
          &lt;Facebook&gt;10190&lt;/Facebook&gt;
          &lt;Twitter&gt;345&lt;/Twitter&gt;
          &lt;GPlus&gt;262&lt;/GPlus&gt;
      &lt;/scores&gt;
      &lt;headline&gt;Wikipedia lÃ¶scht FDP-Eintrag wegen fehlender Relevanz&lt;/headline&gt;
      &lt;description&gt;Berlin (dpo) - Das ging schnell. Seit gestern existiert der Wikipedia-Eintrag der FDP nicht mehr. Der mit knapp 10.000 WÃ¶rtern durchaus umfangreiche Beitrag wurde nach einer kurzen LÃ¶schdiskussion entfernt, weil er den strengen Relevanzkriterien des Online-Lexikons nicht mehr standhalten konnte. FÃ¼r marginale Splitterparteien und Kleinstgruppierungen wie die Liberalen sei kein Platz in der Wikipedia. [Weiterlesen]&lt;/description&gt;
      &lt;articleURL&gt;http://www.der-postillon.com/2013/09/wikipedia-loscht-fdp-eintrag-wegen.html&lt;/articleURL&gt;
      &lt;sourceURL&gt;&lt;![CDATA[http://www.der-postillon.com]]&gt;&lt;/sourceURL&gt;
      &lt;imageURL&gt;&lt;![CDATA[http://www.10000flies.de/images/nopic.jpg]]&gt;&lt;/imageURL&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>But I don't seem to find a good solution to handle this. But I bet this is super easy. I just can't find it. Alternatively you could give me an easy tutorial on how to read an XML file from a local folder and work with it.</p>