2011-10-11 91 views
2

我一直在嘗試使用此處找到的SAX解析器解析此網址(http://app.calvaryccm.com/mobile/android/v1/devos):http://android-er.blogspot.com/2010/05/simple-rss-reader-iii-show-details-once.html我一直在研究如何處理XML中的描述標記。我試過這個,沒有CDATA標籤,似乎沒有任何幫助。這就像鏈接正被讀入描述一樣。使用SAX解析器進行Android XML解析

第一部分工作得很好:當我嘗試訪問內部頁面

enter image description here

的問題發生。就好像鏈接標籤在描述標籤之前被讀取一樣。

enter image description here

我在獲得描述標籤,以顯示正確的有一個問題。感謝您的幫助!

編輯此應用程序的完整的源代碼是在這裏:http://dl.dropbox.com/u/19136502/CCM.zip

+0

您是否使用與示例相同的代碼?如果您編輯了代碼,請在此處提供。 –

+0

你想從描述標籤中得到什麼值?和任何其他值 –

+1

「對不起,此下載鏈接不再存在」....來自http:// justbeamit.com/95152' –

回答

3

哎喲,約3小時挖掘和分析你的源代碼後,我發現你爲什麼有這樣一個奇怪的結果,像上面的原因。

首先看看來自鏈接的RSS內容你解析:http://app.calvaryccm.com/mobile/android/v1/devos

其內容的某些部分:

<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>CCM Daily Devotions</title> <link>http://www.calvaryccm.com/resources/dailydevotions.aspx</link> <description>Calvary Chapel Melbourne's Daily Devotionals</description> <webMaster>[email protected] (Calvary Chapel Melbourne)</webMaster> <copyright>(c)2011, Calvary Chapel Melbourne. All rights reserved</copyright> <ttl>60</ttl> <item> <guid isPermaLink="false">b3e91cbf-bbe9-4667-bf4c-8ff831ba09f1</guid>
<title>Teachable Moments</title> <description>Based on &amp;ldquo;Role Models, Part 4&amp;rdquo; by Pastor Mark Balmer; 10/8-9/11, Message #6078; Daily Devotional #6 - &amp;ldquo;Teachable Moments&amp;rdquo; Preparing the Soil (Introduction): My husband and I took seriously our understanding of God&amp;rsquo;s instructions to teach His commandments to our children. (Deuteronomy 6:7) We went to our local Christian bookstore and bought children&amp;rsquo;s Bibles, studies, coloring books, games&amp;mdash;anything that would help us to communicate biblical situations in their lives. Planting and Watering the Seed (Growth): Each parent needs to take seriously God&amp;rsquo;s commthe Crop (Action/Response): Life is God&amp;rsquo;s classroom for teachable moments. A long delay in traffic can be a frustrating irritation, or it can be an opportunity to teach our children that God&amp;rsquo;s than taught. Cultivating (Additional Reading): Psalm 78:1-8;&amp;nbsp;Psalm 145:4 klw Calvary Chapel of Melbourne; 2955 Minton Road; W. Melbourne, FL 32904; 321-952-9673 NLT = New Living Translation. </description> <link>http://www.calvaryccm.com/resources/dailydevotions.aspx</link> <pubDate>Sun, 16 Oct 2011 12:00:00 GMT</pubDate> </item>

注重緊密合作,以這個標籤/rss/channel/item/description,你能看到的是這些東西:rsquo;'squo;&amp;ldquo;rdquo; ...這些是轉義字符(左單引號,右單引號,&符號,右雙引號,左雙引號e引用...甚至是新行),它們都駐留在XML內容中。

所以當XML Parser通過這些字符時,它認爲要逃避解析,這會導致你現在面臨的怪異結果。

解決方案如何?起初,我可以考慮首先獲取URL的內容,然後使用這些字符(添加SLASH字符),現在我認爲您可以再次成功解析它。
但是,這種解決方案似乎工作得很好,但我認爲它可能不會,因爲來自服務器的RSS文本內容響應格式很奇怪(格式不正確)。因此,如果您可以聯繫此Web管理員,請在發佈RSS訂閱前告訴他們很好地格式RSS content(如添加SLASH以轉義字符,刪除所有NEW-LINE字符...)。

其他的解決方案是使用手柄逃避某些第三方/轉義東西像StringEscapeUtilsApache Commonshttp://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.htmlJTidy
但我不認爲這些庫在你的情況下效果最好。

這就是我所能說的。

@ p/s:對您的源代碼只是一些評論,我認爲您需要考慮清楚您的代碼以便閱讀,更好地進行維護,並適當重新打包。

+0

看看我改進的RSS源,這就是問題[http://app.calvaryccm.com/mobile/android/v1/devos](http://app.calvaryccm.com/mobile/android/v1/狄維士) –