1

我知道有很多关于在 android 中解析 CDATA 的问答。但实际上他们还没有帮助我。我的问题是我无法从 CDATA 获取全部数据。这是我的饲料。

<item>
<title>
SocialStory and Thomson Reuters Foundation TrustLaw Connect Meetup
</title>
<link>
http://yourstory.in/2013/06/socialstory-and-thomson-reuters-foundation-trustlaw-connect-meetup/
</link>
<comments>
http://yourstory.in/2013/06/socialstory-and-thomson-reuters-foundation-trustlaw-connect-meetup/#comments
</comments>
<pubDate>Wed, 12 Jun 2013 04:21:54 +0000</pubDate>
<dc:creator>Vallabh Rao</dc:creator>
<category>
<![CDATA[ Events ]]>
</category>
<guid isPermaLink="false">http://yourstory.in/?p=75912</guid>
<description>
<![CDATA[
SocialStory, the social entrepreneurship and impact investing sector media platform of YourStory.in, is organizing a meetup with Thomson Reuters Foundation TrustLaw Connect programme at the YourStory.in office on 21st June, 2013 from 2:30PM to 4:30PM. Mumbai based Program Manager at Trust Law at Thomson Reuters Foundation, Urvashi Devidayal  will be interacting with and taking questions [...] <a class="read-more" href="http://yourstory.in/2013/06/socialstory-and-thomson-reuters-foundation-trustlaw-connect-meetup/">Read More</a>
]]>
</description>
<content:encoded>
<![CDATA[
<p>SocialStory, the social entrepreneurship and impact investing sector media platform of YourStory.in, is organizing a meetup with Thomson Reuters Foundation TrustLaw Connect programme at the YourStory.in office on 21st June, 2013 from 2:30PM to 4:30PM. Mumbai based Program Manager at Trust Law at Thomson Reuters Foundation, Urvashi Devidayal  will be interacting with and taking questions about the programme from interested social enterprise and non-profit representatives.</p> <p>TrustLaw Connect is the Thomson Reuters Foundation&#8217;s global pro bono service that amplifies the impact of NGOs and social enterprises by connecting them with the best lawyers around the world. Launched in 2010, TrustLaw Connect has grown to include over 1,200 members in 120 countries.</p> <p><a href="http://social.yourstory.in/2013/06/socialstory-and-thomson-reuters-foundation-trustlaw-connect-meetup/" target="_blank">Click here to read more and register to attend. </a></p>
]]>
</content:encoded>
<wfw:commentRss>
http://yourstory.in/2013/06/socialstory-and-thomson-reuters-foundation-trustlaw-connect-meetup/feed/
</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>

我想获取</content:encoded>标签内的所有数据,尤其是图像源。我不知道如何得到它。

这是我的RSSHandler课。

public class RSSHandler extends DefaultHandler {

    final int state_unknown = 0;
    final int state_title = 1;
    final int state_description = 2;
    final int state_link = 3;
    final int state_pubdate = 4;
    final int state_creator= 5;
    final int state_encoded =6;
    int currentState = state_unknown;

    static String encoded_text = " ";

    RSSFeed feed;
    RSSItem item;

    boolean itemFound = false;

    RSSHandler(){
    }

    RSSFeed getFeed(){
        return feed;
    }

    @Override
    public void startDocument() throws SAXException {
        // TODO Auto-generated method stub
        feed = new RSSFeed();
        item = new RSSItem();

    }

    @Override
    public void endDocument() throws SAXException {
        // TODO Auto-generated method stub
    }

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        // TODO Auto-generated method stub

        if (localName.equalsIgnoreCase("item")){
            itemFound = true;
            item = new RSSItem();
            currentState = state_unknown;
        }
        else if (localName.equalsIgnoreCase("title")){
            Log.e("node_title",localName);
            currentState = state_title;
        }
        else if (localName.equalsIgnoreCase("description")){
            currentState = state_description;
        }
        else if (localName.equalsIgnoreCase("link")){
            currentState = state_link;
        }
        else if (localName.equalsIgnoreCase("pubdate")){
            currentState = state_pubdate;
        }
        else if (localName.equalsIgnoreCase("creator")){

            currentState = state_creator;
        }

        else{
            currentState = state_unknown;
        }

    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        // TODO Auto-generated method stub
        if (localName.equalsIgnoreCase("item")){
            feed.addItem(item);
        }
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        // TODO Auto-generated method stub

        String strCharacters = new String(ch,start,length);

        if (itemFound==true){
            // "item" tag found, it's item's parameter
            switch(currentState){
            case state_title:
                item.setTitle(strCharacters);

                Log.e("title",strCharacters);
                break;
            case state_description:
                item.setDescription(strCharacters);
                break;
            case state_link:
                item.setLink(strCharacters);
                break;
            case state_pubdate:
                item.setPubdate(strCharacters);
                break;
            case state_creator:
                item.setCreator(strCharacters);
                break;

            default:
                break;
            }
        }
        else{
            // not "item" tag found, it's feed's parameter
            switch(currentState){
            case state_title:
                feed.setTitle(strCharacters);
                break;
            case state_description:
                feed.setDescription(strCharacters);
                break;
            case state_link:
                feed.setLink(strCharacters);
                break;
            case state_pubdate:
                feed.setPubdate(strCharacters);
                break;  
            case state_creator:
                feed.setCreator(strCharacters);
                break;

            default:
                break;
            }
        }

        currentState = state_unknown;
    }



}
4

0 回答 0