1

android.util.Xml.parse(InputStream, Encoding, ContentHandlerこのRSSフィードを解析するためにAndroidのXML解析ヘルパー()を使用しています:http: //www.rssweather.com/wx/nz/christchurch/rss.phpcontent:encoded取得しようとしているデータが含まれているタグを認識していないようです。XMLの構造は次のとおりです。

<rss>
    <channel>
        <item>
            <title>...</title>
            <pubDate>...</pubDate>
            // Other tags
            <content:encoded>
                <![CDATA[
                    (.... this is what I want to retrieve ...)
                ]]>
            </content:encoded>
        </item>
    </channel>
</rsss>

これは私のコードです:

void parse(){
    RootElement root = new RootElement("rss");
    Element channel = root.getChild("channel");
    Element item = channel.getChild("item");
    Element contentEncoded = item.getChild("content", "encoded");
    // Have also tried these two:
    Element encoded = item.getChild("encoded");
    Element content = item.getChild("content");

    contentEncoded.setEndTextElementListener(new EndTextElementListener() {
        public void end(String body) {
            Log.d("Test", "Content found: " + body);
        }
    });


    try {
        Xml.parse(feedUrl.openConnection().getInputStream(),
                Xml.Encoding.UTF_8, root.getContentHandler());
    } catch (Exception e){
        throw new RuntimeException(e);
    }
}

どこが間違っているのですか?<item>: )titleやpubDateなどの要素から他のデータを問題なく取得できます。私を逃れるのはcontent:encodedだけです。

4

2 に答える 2

3

AndroidSaxParserを使い続けることができます。同じ問題と、コンテンツの名前空間を使用して要素として「エンコード」するという解決策に直面しました。

コンテンツの名前空間はrss要素にあります。

<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/" ... >

したがって、要素の取得は次のようになります。

item.getChild("http://purl.org/rss/1.0/modules/content/", "encoded");
于 2012-06-06T13:48:00.437 に答える
0

...「content:encoded」は要素の有効な名前ではないと思います。「コンテンツ」が名前空間であり、この名前空間の要素を「エンコード」している場合、それは有効です。

于 2012-05-04T22:18:26.387 に答える