Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中解析RSS源中的CDATA_Android_Xml Parsing_Cdata - Fatal编程技术网

在android中解析RSS源中的CDATA

在android中解析RSS源中的CDATA,android,xml-parsing,cdata,Android,Xml Parsing,Cdata,我知道有很多关于android解析CDATA的问答。但实际上他们还没有帮我。我的问题是,我无法从CDATA获取全部数据。这是我的饲料 <item> <title> SocialStory and Thomson Reuters Foundation TrustLaw Connect Meetup </title> <link> http://yourstory.in/2013/06/socialstory-and-thomson-reuters-f

我知道有很多关于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>

如果你知道这是一个重复的问题,那么你为什么要问这个问题这些答案对我没有帮助。我试了很多:(:D)第二个呢?但是
内容:encoded
标签中的CDATA呢?它可能包含
.

.
等等。。
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;
    }



}