Homework 3
|
Modified: |
Download
Overview
The assignment provides experience implementing on a mobile device using:
- XML as a data source.
- SAX event-driven parser
- RESTful service
The vehicle for the assignment is accessing a stock database provided as a RESTful service. The mobile application accepts a stock symbol and displays the stock info and chart.
Example: a RESTful Stock Quote service
A RESTful stock quote service returns XML of stock data given a stock symbol.
For example the Google service request: http://www.google.com/ig/api?stock=AAPL
<?xml version="1.0" ?><symbol data="AAPL" /><pretty_symbol data="AAPL" /><symbol_lookup_url data="/finance?client=ig&q=AAPL" /><company data="Apple Inc." /><exchange data="Nasdaq" /><exchange_timezone data="ET" /><exchange_utc_offset data="+05:00" /><exchange_closing data="960" /><divisor data="2" /><currency data="USD" /><last data="335.22" /><high data="340.95" /><low data="335.02" /><volume data="12078244" /><avg_volume data="14549" /><market_cap data="308830.81" /><open data="339.56" /><y_close data="340.53" /><change data="-5.31" /><perc_change data="-1.56" /><delay data="0" /><trade_timestamp data="May 20, 2011" /><trade_date_utc data="20110520" /><trade_time_utc data="200018" /><current_date_utc data="20110522" /><current_time_utc data="024936" /><symbol_url data="/finance?client=ig&q=AAPL" /><chart_url data="/finance/chart?q=NASDAQ:AAPL&tlf=12" /><disclaimer_url data="/help/stock_disclaimer.html" /><ecn_url data="" /><isld_last data="" /><isld_trade_date_utc data="" /><isld_trade_time_utc data="" /><brut_last data="" /><brut_trade_date_utc data="" /><brut_trade_time_utc data="" /><daylight_savings data="true" /></finance></xml_api_reply>Note the last quoted stock value:
<last data="335.22" />and the chart is defined as:
<chart_url data="/finance/chart?q=NASDAQ:AAPL&tlf=12" />and viewable at:
ASSIGNMENT
Implement a mobile application on an Android or iOS device that accesses the Google stock service, parses the returned XML using SAX, and given a user entered stock symbol displays:
- company name,
- last data,
- and today's trading chart.
HINTS Android
In the following, sName is the name of the starting element and attrs is an array of attributes.
| public void startElement(String namespaceURI, String sName, //
simple name String qName, // qualified name Attributes attrs) throws SAXException { |
HINTS iOS
In the following, elementName is the name of the starting element and attributeDict is an NSDictionary of attributes.
| - (void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"last"]) NSLog(@"attribute value %@\n", [attributeDict valueForKey: @"data"]); } |
TURN IN
Upload a single compressed directory named HW3.zip containing the complete project to OnCourse dropbox.