溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Android XML提要怎么實(shí)現(xiàn)

發(fā)布時(shí)間:2021-12-18 17:00:07 來(lái)源:億速云 閱讀:301 作者:iii 欄目:移動(dòng)開發(fā)

本篇內(nèi)容介紹了“Android XML提要怎么實(shí)現(xiàn)”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

通過(guò)允許日期和鏈接作為簡(jiǎn)單的對(duì)象被訪問(wèn),同時(shí)將它們表示為較強(qiáng)類型的對(duì)象(de  >java.util.Datede > 和 de >java.net.URLde  >),它隱藏了一些內(nèi)部狀態(tài)。它是一個(gè)典型的 Value Object,因此它基于其內(nèi)部狀態(tài)實(shí)現(xiàn)了 de >equals()de  > 和 de >hashCode()de >。它還實(shí)現(xiàn)了 de >Comparablede >  接口,因此您可以使用它進(jìn)行排序(按日期)。在實(shí)踐中,提要中的數(shù)據(jù)始終是有序的,因?yàn)闆](méi)有必要再進(jìn)行排序。

每個(gè)解析器實(shí)現(xiàn)都需要提供一個(gè) URL 給 Androidster 提要,并使用它打開一個(gè)到 Androidster 站點(diǎn)的 HTTP 連接。這一常見行為自然是在 Java 代碼中建模,我們使用了一個(gè)抽象基類,所示。

基本提要解析器類

java代碼:

public abstract class BaseFeedParser implements FeedParser { // names of the XML tags static final String PUB_DATE = "pubDate"; static final String DESCRIPTION = "description"; static final String LINK = "link"; static final String TITLE = "title"; static final String ITEM = "item"; final URL feedUrl; protected BaseFeedParser(String feedUrl){ try { this.feedUrl = new URL(feedUrl); } catch (MalformedURLException e) { throw new RuntimeException(e); } } protected InputStream getInputStream() { try { return feedUrl.openConnection().getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } } }

基類存儲(chǔ) de >feedUrlde > 并使用它打開了一個(gè) de >java.io.InputStreamde  >。如果出現(xiàn)任何差錯(cuò),它會(huì)拋出一個(gè) de >RuntimeExceptionde  >,造成應(yīng)用程序出現(xiàn)故障?;愡€為標(biāo)記的名稱定義了一些簡(jiǎn)單的常量。顯示了提要中的一些示例內(nèi)容,以便于您理解這些標(biāo)記的重要性。

示例 XML 提要

java代碼:

  1. < ?xml version="1.0" encoding="UTF-8"? > 

  2. < !-- generator="FeedCreator 1.7.2" -- > 

  3. < rss version="2.0" > 

  4. < channel > 

  5. < title >android_news< /title > 

  6. < description >android_news< /description > 

  7. < link >< /link > 

  8. < lastBuildDate >Sun, 19 Apr 2009 19:43:45 +0100< /lastBuildDate > 

  9. < generator >FeedCreator 1.7.2< /generator > 

  10. < item > 

  11. < title >Samsung S8000 to Run Android, Play DivX, Take Over the World< /title > 

  12. < link >< /link > 

  13. < description >More details have emerged on the first Samsung handset 

  14. to run Android. A yet-to-be announced phone called the S8000 is being 

  15. reported ...< /description > 

  16. < pubDate >Thu, 16 Apr 2009 07:18:51 +0100< /pubDate > 

  17. < /item > 

  18. < item > 

  19. < title >Android Cupcake Update on the Horizon< /title > 

  20. < link >< /link > 

  21. < description >After months of discovery and hearsay, the Android 

  22. build that we have all been waiting for is about to finally make it 

  23. out ...< /description > 

  24. < pubDate >Tue, 14 Apr 2009 04:13:21 +0100< /pubDate > 

  25. < /item > 

  26. < /channel > 

  27. < /rss >

“Android XML提要怎么實(shí)現(xiàn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI