|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 10/28/2009 at 09:31AM PDT, ID: 24851595 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [months count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [games count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"Default";
}
- (void)parseXMLFileAtURL:(NSString *)URL
{
games = [[NSMutableArray alloc] init];
months = [[NSMutableArray alloc] init];
//you must then convert the path to a proper NSURL or it won't work
//NSURL *xmlURL = [NSURL URLWithString:URL];
NSString *Path = [[NSBundle mainBundle]bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Schedule.xml"];
NSData *Data = [[NSData alloc]initWithContentsOfFile:DataPath];
// here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
// this may be necessary only for the toolchain
rssParser = [[NSXMLParser alloc] initWithData:Data];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[rssParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:@"Month"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
monthName = [[NSMutableString alloc] initWithString:[attributeDict valueForKey:@"name"]];
NSLog(@"Adding A Month with name: %@", monthName);
}
else if ([elementName isEqualToString:@"Game"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
gameDate = [[NSMutableString alloc] init];
gameTime = [[NSMutableString alloc] init];
theHomeTeam = [[NSMutableString alloc] init];
theVisitorTeam = [[NSMutableString alloc] init];
theGameResults = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"Month"]) {
// save values to an item, then store that item into the array...
[item setObject:monthName forKey:@"name"];
[months addObject:[item copy]];
NSLog(@"Adding A New Month %@", monthName);
NSLog(@"months array has %d items", [months count]);
}
else if ([elementName isEqualToString:@"Game"]) {
// save values to an item, then store that item into the array...
[item setObject:gameDate forKey:@"Date"];
[item setObject:theVisitorTeam forKey:@"Visitor"];
[item setObject:theHomeTeam forKey:@"Home"];
[item setObject:gameTime forKey:@"Time"];
[item setObject:theGameResults forKey:@"Results"];
[games addObject:[item copy]];
NSLog(@"Adding Game on date: %@", gameDate);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"Month"])
{
[monthName appendString:string];
}
else if ([currentElement isEqualToString:@"Date"])
{
[gameDate appendString:string];
}
else if ([currentElement isEqualToString:@"Visitor"])
{
[theVisitorTeam appendString:string];
}
else if ([currentElement isEqualToString:@"Home"])
{
[theHomeTeam appendString:string];
}
else if ([currentElement isEqualToString:@"Time"])
{
[gameTime appendString:string];
}
else if ([currentElement isEqualToString:@"Results"])
{
[theGameResults appendString:string];
}
}
|
Advertisement