title: Android - Get attributes from CDATA section using XMLPullParser
body: <p>The xml looks like this (out of a RSS feed):</p>
  
  <pre><code>&lt;description&gt;
  &lt;![CDATA[
  &lt;div&gt;&lt;a href='articleURL'&gt;&lt;img src='pic.jpg' alt='blah blah' title='blah blah' 
  border='0' width='100' height='56'&gt;&lt;/a&gt;&lt;/div&gt;
  ]]&gt;
  gist of the article.....
  &lt;/description&gt;
  </code></pre>
  
  <p>I want to get the following attributes:</p>
  
  <p>img src - holding the article pic</p>
  
  <p>the article gist at the end of the tag but when running I get a NullPointer Ex.</p>
  
  <p>All the rest (outside the CDATA section work just fine...)</p>
  
  <p>the code I used:</p>
  
  <pre><code>class BackgroundParser extends AsyncTask&lt;String, String, Integer&gt;{
      int headlineCount = 0;
      String headlineTitle = "";
      Bitmap pic = null;
      String xmlDate = "";
      String gist = "";
      String articleUrl = "";
      @Override
      protected Integer doInBackground(String... params) {
          // TODO Auto-generated method stub
          try {
              URL rssFeed = new URL(params[0]);
              XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
              XmlPullParser parser = factory.newPullParser();
              InputStream is = rssFeed.openStream();
              parser.setInput(is, null);
              boolean item = false;
              boolean title = false;
              boolean date = false;
              boolean description = false;
              boolean link = false;
              String tagName;
              int eventType = parser.getEventType();
              while(eventType!=XmlPullParser.END_DOCUMENT){
                  if(eventType==XmlPullParser.START_TAG){
                      tagName = parser.getName();
                      if(item){
                          if(tagName.equals("title"))title = true;
                          if(tagName.equals("description")){
                              String img = parser.getAttributeValue(null, "img src");
                              Log.i("Info", img);
                              pic = getBitmapFromURL(img);
  
                          }
                          if(tagName.equals("pubDate"))date = true;
                          if(tagName.equals("description"))description = true;
                          if(tagName.equals("link"))link = true;
                      }
                      else{
                          if(tagName.equals("item"))item = true;
                      }
                  }
                  if(eventType==XmlPullParser.END_TAG){
                      tagName = parser.getName();
                      if(tagName.equals("item")){
                          item = false;
                          headlines.add(new Headline(headlineTitle,xmlDate,pic,gist,articleUrl));
                          headlineTitle = null; xmlDate = null; pic = null; gist = null; articleUrl = null;
                          headlineCount++;
                      }
                  }
                  if(eventType==XmlPullParser.TEXT){
                      if(title){
                          headlineTitle = parser.getText();
                          Log.i("Info", headlineTitle);
                          title = false;
                      }
                      if(date){
                          xmlDate = parser.getText();
                          Log.i("Info", xmlDate);
                          date = false;
                      }
                      if(description){
                          gist = parser.getText();
                          Log.i("info",gist);
                          description = false;
                      }
                      if(link){
                          articleUrl = parser.getText();
                          Log.i("info", articleUrl);
                          link = false;
                      }
                  }
                  eventType = parser.next();
              }
  </code></pre>