Hi all,
I am really struggling on this. I have an XML feed:
<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
<date>
<name>27/9/10</name>
<event>
<title>Event 1</title>
<more>Copy in here</more>
</event>
</date>
<date>
<name>04/10/10</name>
<event>
<title>Event 1</title>
<more>Copy in here</more>
</event>
<event>
<title>Second Event</title>
<more>Copy in here</more>
</event>
</date>
</data>
I can manage to parse the xml with:
- (void)parseXMLFileAtURL:(NSString *)URL {
sections = [[NSMutableArray alloc] init];
items = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser parse];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"event"]) {
currentTitle = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
}
if ([elementName isEqualToString:@"date"]) {
item = [[NSMutableDictionary alloc] init];
currentSection = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"date"]) {
[item setObject:[NSNumber numberWithInt:itemsCount] forKey:@"itemsCount"];
[item setObject:currentSection forKey:@"name"];
[items addObject:[item copy]];
itemsCount = 0;
}
if ([elementName isEqualToString:@"event"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentSummary forKey:@"more"];
[items addObject:[item copy]];
itemsCount = itemsCount + 1;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"name"]) {
[currentSection appendString:string];
} else if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"more"]) {
[currentSummary appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.progressView.view removeFromSuperview];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[dataTable reloadData];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([sections count] == 0) {
NSString * path = @"http://www.campuscloud.co.uk/_dev/calendar.xml";
[self parseXMLFileAtURL:path];
}
}
But when I try and display this in my table it all goes wrong when I display more than two events for the one date. I want the date to show as a section header and the events to be displayed below.
Any help on this welcome...