Article Preview
Buy Now
COLUMN
From Scratch: Finishing StocksSocket
Issue: 2.2 (October/November 2003)
Author: William Leshner
Author Bio: William Leshner has been programming for twenty years and programming Macs for ten. He has spent a good deal of the last several years building REALbasic applications, including the now famous ResPloder.
Article Description: No description available.
Article Length (in bytes): 11,111
Starting Page Number: 40
Article Number: 2219
Resource File(s):
2219.zip Updated: 2013-03-11 19:07:57
Related Web Link(s):
http://content.nasdaq.com/logos/AAPL.GIF<
http://www.w3.org/DOM/
Excerpt of article text...
This is the second in a series of three articles in which we are creating StocksSocket, a subclass of HTTPSocket that obtains stock information from a NASDAQ XML feed. As we discussed in the last article, we can query a NASDAQ server for stock information and the server returns the results as XML. Our StocksSocket will take care of querying the server and parsing the resulting XML. For each stock in the XML, StocksSocket will add the attributes for that stock to a dictionary and then pass the stock symbol and the dictionary to a New Event we called StockReceived. In this article we will talk about how to parse the XML we get from the NASDAQ server and how to pass the result to the StockReceived event.
One word of caution: I had to make a few changes to SimpleXmlParser. It seems that NASDAQ made a minor modification to their XML feed and I had to modify the parser to handle the change. This is a good thing, actually. The current incarnation of SimpleXmlParser should be more robust.
Stock XML
Before we start writing code, let's take a look at a bit of the XML that the NASDAQ server returns as a response to a stock query. Consider this snippet of XML that I obtained from a query for the stock symbol "AAPL":
<nasdaqamex-dot-com>
...End of Excerpt. Please purchase the magazine to read the full article.