DocumentBuilder db newInstance newDocumentBuilder

Documentbuilder db newinstance newdocumentbuilder

This preview shows page 15 - 22 out of 42 pages.

DocumentBuilder db = DocumentBuilderFactory . newInstance(); .newDocumentBuilder(); Document dom = db.parse(someHttpInputStream); DOM Document Object Model Consuming RSS Feeds
Image of page 15
Example : The tree in Figure 2 contains a set of item nodes. Assume dom is the DOM-tree made by parsing the input stream returned by an RSS aggregator. Accessing item data could be done as follows // define access to all nodes in the parse tree Element treeElements = dom.getDocumentElement(); // look for individual news ("items" in this case) // put items in a NodeList collection NodeList itemNodes = treeElements.getElementsByTagName( "item" ); Reference: 16 DOM Document Object Model Consuming RSS Feeds
Image of page 16
In particular, the often used java.net class HttpUrlConnection follows the next steps: 1. Obtain a new HttpURLConnection 2. Prepare the request (URI including header, credentials, content, cook ies…) 3. Read the response (non-buffered stream returned by getInputStream() ) 4. Disconnect as soon as response is read. HTTP Processing in Android Android s handling of HTTP network resources is typically done using either of the client-side included APIs 1. Standard Java network java.net package, and/or 2. Apache HttpClient library. Consuming RSS Feeds References: 17
Image of page 17
In this project we will develop an application to expose on Android devices the public-access RSS material aggregated by National Public Radio ( NPR ). Internet National Public Radio RSS Web Feeds Example. All things consider ed’ Consuming RSS Feeds 18
Image of page 18
19 Step1 . A little research shows that NPR supports a number of web feeds, among them the following: Example. NPR Project Action Plan Consuming RSS Feeds Topic URL Top Stories U.S. News World News Business Health & Science Arts & Entertainment Politics & Society People & Places Opinion
Image of page 19
Step2. We will display on a ListView widget, a basic menu consisting of a fixed set of topics (for instance: Top Stories, US News, World News, Business, etc) We wait for the user to make a selection. Once a category is chosen its corresponding headlines will be downloaded. Choose “Heal th & Science” Example. NPR Project Action Plan Consuming RSS Feeds 20
Image of page 20
Step3 . Again, a simple ListView box is used to show the most current headlines from the selected category (notice the TextSize is now slightly smaller). The user can scroll the list and click on a particular story.
Image of page 21
Image of page 22

You've reached the end of your free preview.

Want to read all 42 pages?

  • Fall '12
  • JoshuaO'Connor
  • Atom, Web feed, RSS feeds, Aggregator

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture