2011-10-11 90 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/狄维士) –