I have deviated from my book, which was a mistake.....
I discovered a stock API from Google yesterday that returns various bits of information about a stock in what I think is XML. I set about reading up on the NSXMLParser class.
I have had some success. The following code successfully prints the top level element names of what is returned, and then attempts to print the value associated with the element name:
However, the following just returns (null):
I was able to view what the API returned on my work laptop in internet explorer, but it doesn't seem to appear when I view in Safari at home. So, from memory, there are no further "levels" past the first tier of element names. "last" should return the last retrieved stock price; there isn't another list of elements below "last", only the actual value.
For information, this is how the NSXMLParser object is initialised and set off doing it's thing:
.. and urlString is, say, http://www.google.com/ig/api?stock=AAPL.
Please could anyone explain why I cannot retrieve the stock price value from "last" (or indeed any of the other element names that I have tried this with)?
Thank you
I discovered a stock API from Google yesterday that returns various bits of information about a stock in what I think is XML. I set about reading up on the NSXMLParser class.
I have had some success. The following code successfully prints the top level element names of what is returned, and then attempts to print the value associated with the element name:
Code:
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
NSLog(@"%@", elementName);
NSEnumerator *dictEnumerator = [attributeDict keyEnumerator];
id selectedKey;
if ([elementName isEqualToString:@"last"]) {
while (selectedKey = [dictEnumerator nextObject]) {
NSLog(@"%@", [attributeDict objectForKey:elementName]);
}
}
}
However, the following just returns (null):
Code:
NSLog(@"%@", [attributeDict objectForKey:elementName]);
I was able to view what the API returned on my work laptop in internet explorer, but it doesn't seem to appear when I view in Safari at home. So, from memory, there are no further "levels" past the first tier of element names. "last" should return the last retrieved stock price; there isn't another list of elements below "last", only the actual value.
For information, this is how the NSXMLParser object is initialised and set off doing it's thing:
Code:
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
BOOL parseSuccess = [parser parse];
[parser setDelegate:nil];
.. and urlString is, say, http://www.google.com/ig/api?stock=AAPL.
Please could anyone explain why I cannot retrieve the stock price value from "last" (or indeed any of the other element names that I have tried this with)?
Thank you