DocumentBuilder db = DocumentBuilderFactory .newInstance();.newDocumentBuilder(); Document dom = db.parse(someHttpInputStream); DOM –Document Object ModelConsuming RSS Feeds
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 collectionNodeList itemNodes = treeElements.getElementsByTagName("item"); Reference:16 DOM –Document Object ModelConsuming RSS Feeds
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, cookies…)3. Read the response (non-buffered stream returned by getInputStream() ) 4. Disconnect as soon as response is read. HTTP Processing in AndroidAndroid’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
In this project we will develop an application to expose on Android devices the public-access RSS material aggregated by National Public Radio (NPR). InternetNational Public Radio RSS Web Feeds Example. ‘All things considered’Consuming RSS Feeds 18
19 Step1. A little research shows that NPR supports a number of web feeds, among them the following: Example. NPR Project –Action PlanConsuming RSS Feeds TopicURLTop Stories U.S. News World News Business Health & Science Arts & Entertainment Politics & Society People & Places Opinion
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 “Health & Science”Example. NPR Project –Action PlanConsuming RSS Feeds 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.