Homework 3
XML Parsing and
RESTful Services

Modified

Download

Overview

The assignment provides experience implementing on a mobile device using:

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" ?>
- <xml_api_reply version="1">
- <finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="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:

http://www.google.com/finance/chart?q=NASDAQ:AAPL&tlf=12

 

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:

  1. company name,
  2. last data,
  3. and today's trading chart.

HINTS Android

  1. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
     
  2. Look over the notes on URL Images and Parsing XML. There are useful examples.
     
  3. The XML data returned from Google contains a single attribute named data for each element, which makes parsing simpler.

    Only startElement method is needed to capture the necessary attribute values.

    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 {
  4. The example UI was purposely designed to provide opportunity for improvement.

HINTS iOS

  1. Look over the notes on URL Images, Parsing XML and NSXMLParser. There are useful examples.
     
  2. The XML data returned from Google contains a single attribute named data for each element, which makes parsing simpler.

    Only startElement method is needed to capture the necessary attribute values.

    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"]);
    }
  3. You will need to dismiss the keyboard, see notes for an example.
     
  4. The example UI was purposely designed to provide opportunity for improvement.

TURN IN

    Upload a single compressed directory named HW3.zip containing the complete project to OnCourse dropbox.