title: Parse CDATA with XMLParser in this specific case for ANDROID
body: <p>I've seen quite a few posts about this, but actually I did not get any to work. I am building a simple TV guide android application. I simply Use RSS from a tvprofil.net to show whats on TV today. The problem is, I do not know how to Parse CDATA in XML. I am using some standard parser with DOM... at least I think so..</p>
  
  <p>This is a bit of XML:</p>
  
  <pre><code>.
  .
  .
  &lt;item&gt;
  &lt;title&gt;RTS1 14.08.2012&lt;/title&gt;
  &lt;pubDate&gt;Tue, 14 Aug 2012 06:00:00&lt;/pubDate&gt;
  &lt;content:encoded&gt;&lt;![CDATA[06:00 Vesti&lt;br&gt;06:05 Jutarnji program&lt;br&gt;08:00 Dnevnik
  &lt;br&gt;8:15 Jutarnji Program&lt;br&gt;09:00 Vesti ... ]]&gt;&lt;/content:encoded&gt;
  &lt;/item&gt;
  .
  .
  .
  </code></pre>
  
  <p>now, this is my main app:</p>
  
  <pre><code>public class Main extends ListActivity {
  
  // All static variables
  static final String URL = "http://tvprofil.net/rss/feed/channel-group-2.xml";
  // XML node keys
  static final String KEY_ITEM = "item"; // parent node
  static final String KEY_NAME = "title";
  static final String KEY_DATE = "pubDate";
  static final String KEY_DESC = "content:encoded";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      ArrayList&lt;HashMap&lt;String,String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  
  
  
      XMLParser parser = new XMLParser();
      String xml = parser.getXmlFromUrl(URL); //get XML
      Document doc = parser.getDomElement(xml); // get DOM elem.
  
  
  
      NodeList nl = doc.getElementsByTagName(KEY_ITEM);
      //loop
      for (int i=0; i&lt; nl.getLength(); i++){
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          Element e = (Element) nl.item(i);
          //add to map
          map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
          map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
          map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
  
          // hash =&gt; list
          menuItems.add(map);
      }
  
      ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.list_item,
              new String[]{KEY_NAME, KEY_DESC, KEY_DATE}, new int[]{
              R.id.name, R.id.description, R.id.date
      });
      setListAdapter(adapter);
  
      //singleView
      ListView lv = getListView();
  
      lv.setOnItemClickListener(new OnItemClickListener(){
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id){
              String name = ((TextView)view.findViewById(R.id.name)).getText().toString();
              String date = ((TextView)view.findViewById(R.id.date)).getText().toString();
              String description = ((TextView)view.findViewById(R.id.description)).getText().toString();
  
              //intent
              Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
              in.putExtra(KEY_NAME, name);
              in.putExtra(KEY_DATE, date);
              in.putExtra(KEY_DESC, description);
              startActivity(in);
          }
      });
  
  }
  
  }
  </code></pre>
  
  <p>and the parser class:</p>
  
  <pre><code>public class XMLParser {
  
  // constructor
  public XMLParser() {
  
  }
  
  /**
   * Getting XML from URL making HTTP request
   * @param url string
   * */
  public String getXmlFromUrl(String url) {
      String xml = null;
  
  
      try {
          // defaultHttpClient
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(url);
  
          HttpResponse httpResponse = httpClient.execute(httpPost);
          HttpEntity httpEntity = httpResponse.getEntity();
          xml = EntityUtils.toString(httpEntity);
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      // return XML
      return xml;
  }
  
  /**
   * Getting XML DOM element
   * @param XML string
   * */
  
  public Document getDomElement(String xml){
  
      Document doc = null;
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      try {
  
          DocumentBuilder db = dbf.newDocumentBuilder();
  
          InputSource is = new InputSource();
              is.setCharacterStream(new StringReader(xml));
              doc = db.parse(is); 
  
          } catch (ParserConfigurationException e) {
              Log.e("Error: ", e.getMessage());
              return null;
          } catch (SAXException e) {
              Log.e("Error: ", e.getMessage());
              return null;
          } catch (IOException e) {
              Log.e("Error: ", e.getMessage());
              return null;
          }
  
          return doc;
  }
  
  /** Getting node value
    * @param elem element
    */
   public final String getElementValue( Node elem ) {
  
       Node child;
       if( elem != null){
           if (elem.hasChildNodes()){
               for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
                   if( child.getNodeType() == Node.TEXT_NODE  ){
                       return child.getNodeValue();
                   }
               }
           }
       }
       return "";
   }
  
   /**
    * Getting node value
    * @param Element node
    * @param key string
    * */
   public String getValue(Element item, String str) {     
          NodeList n = item.getElementsByTagName(str);        
          return this.getElementValue(n.item(0));
      }
  }
  </code></pre>
  
  <p>there is one more class for Single menu item.. but I think it's irrelevant in this case.
  Now, I'd just like to see no HTML tags after parsing it and dealing with CDATA...
  Anyone got idea about this one?</p>