Results 1 to 1 of 1
  1. #1
    snomen is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default Parsing the CDATA section in XML using XML Pull Parser

    Sample XML

    <feed xmlns="">
    <title>NDTV News - Top Stories</title>
    <description>Latest entries</description>
    <pubDate>Wed, 31 Jul 2013 22:33:00 GMT</pubDate>
    <lastBuildDate>Wed, 31 Jul 2013 22:33:00 GMT</lastBuildDate>

    <title>Narendra Modi to be BJP's PM candidate, announcement before crucial assembly polls: sources</title>
    <published>Wed, 31 Jul 2013 13:58:31 GMT</published>
    <content ><![CDATA[<div align="center"><a href=" Shatrughan_Sinha_agency_120.jpg"><img border="0" src="" alt="2013-07-29-08-43-05" /></a></div><p><span style="font-size: large;">Narendra Modi could be named the BJP's candidate for Prime Minister for 2014 as early as September this year, party sources have said.</span><br /><br /><span style="font-size: large;"> The party sees the Gujarat Chief Minister as its star vote catcher and reportedly wants to cash in on his popularity in the Assembly elections in four big states at the end of this year. So, the sources said, a Modi announcement could be expected before the notification of the Assembly elections, expected around September 21. </span><br /><br /><span style="font-size: large;">Today, BJP president Rajnath Singh will meet senior Rashtriya Swayamsevak Sangh or RSS leaders, including chief Mohan Bhagwat. He is expected to finalise the party's blueprint for the elections at that meeting, and, as part of that exercise, get a go-ahead on Mr Modi's anointment. </span><br /><br /></p>]]></content>

    With the below code I was able to retrieve <title>, <published> and <author> values within the <entry> tag.

    Java Code:
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();  
                    private XmlPullParser parser = factory.newPullParser();  
                    private InputStream urlStream = downloadUrl(urlString);  
                    parser.setInput(urlStream, null);  
                    int eventType = parser.getEventType();  
                    boolean done = false;  
                    while (eventType != XmlPullParser.END_DOCUMENT && !done) {  
                        tagName = parser.getName();  
                        switch (eventType) {  
                        case XmlPullParser.START_DOCUMENT:                    
                        case XmlPullParser.START_TAG:  
                            if (tagName.equals("entry")) {                        
                            if (tagName.equals("title")) {  
                                title = parser.nextText().toString();  
                                Log.i(TITLE, title);  
                            if (tagName.equals("published")) {  
                                pubDate = parser.nextText().toString();  
                                Log.i(PUBLISHEDDATE, pubDate);  
                            if (tagName.equals("author")) {  
                                Log.i(AUTHOR, author);  
                        case XmlPullParser.END_TAG:  
                            if (tagName.equals("feed")) {  
                                done = true;  
                            } else if (tagName.equals("entry")) {  
                                rssFeed = new RssFeedStructure(title);  
                        eventType =;  
                    private String readAuthor(XmlPullParser parser) throws IOException,  
                        XmlPullParserException {  
                        parser.require(XmlPullParser.START_TAG, null, "name");  
                        author = parser.nextText().toString();  
                        parser.require(XmlPullParser.END_TAG, null, "name");  
                        return author;  

    From the <content> tag how can I retrieve the text value(Narendra Modi could be named the BJP's candidate for.....) from the <p><span> tag?
    Last edited by snomen; 08-14-2013 at 10:40 AM.

Similar Threads

  1. How to put XML data inside CData
    By sbutt in forum XML
    Replies: 0
    Last Post: 06-27-2012, 06:13 PM
  2. Replies: 0
    Last Post: 04-04-2012, 04:35 PM
  3. Replies: 0
    Last Post: 11-13-2009, 09:51 PM
  4. Sending [CDATA] element with SOAP message
    By suchismitasuchi in forum Advanced Java
    Replies: 0
    Last Post: 01-19-2009, 10:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts