I exit one of the source tags in your question, NSXMLParser .
So, suppose you have (a) a mutable array of speeches ; (b) a mutable dictionary for the current speech ; (c) a variable array of lines for each speech; and (d) a mutable value string that will capture characters found between the beginning of the element name and the end of the name of this element.
Then you must implement the NSXMLParserDelegate methods. For example, when analyzing in didStartElement , if you come across the name of a speech element, you create a dictionary:
if ([elementName isEqualToString:@"SPEECH"]) { speech = [[NSMutableDictionary alloc] init]; lines = [[NSMutableArray alloc] init]; } else { value = [[NSMutableString alloc] init]; }
When you come across characters in foundCharacters , you add them to value :
[value appendString:string]
And in didEndElement , if you came across a speaker, set it, if you came across a line, add it, and if you came across a speech closing tag, add speech (with its SPEAKER and lines to your speech array:
if ([elementName isEqualToString:@"SPEAKER"]) { [speech setObject:value forKey:@"SPEAKER"]; } else if ([elementName isEqualToString:@"LINE"]) { [lines addObject:value]; } else if ([elementName isEqualToString:@"SPEECH"]) { [speech setObject:lines forKey:@"LINES"]; [speeches addObject:speech]; speech = nil; lines = nil; } value = nil;
For more information, see the Event-Based Programming Guide or google NSXMLParser Tutorial.
source share