I've read some of the other answers on here, but I can't seem to find what my problem is. I'm trying to hook up to the TFL XML feed using an NSXMLParser. I've created a parser class that implements the NSXMLParserDelegate.
It parses through the XML fine, but when it comes to adding to the Array, different permuatations of what I have done have either added nothing to the array, continuously overwritten the same object in the array or else added a new object to the array whilst overwriting all existing objects in the array
Every TubeLine has a name property, and from stepping through the code, the name property of all 'TubeLine' objects changes when the `self.currentParsedStringDataz changes.
Appreciate any help!
- (instancetype)initWithData:(NSData *)parseData {
self = [super init];
if (self) {
_tubeLineData = [parseData copy];
self.parsedTubeLines = [[NSMutableArray alloc] init];
self.currentParsedStringData = [[NSMutableString alloc] init];
}
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:kEntryElementName]) {
TubeLine *tubeLine = [[TubeLine alloc] init];
self.tubeLine = tubeLine;
} else if ([elementName isEqualToString:kNameElementName]) {
_accumulatingParsedCharacterData = YES;
[self.currentParsedStringData setString:@""];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:kEntryElementName]) {
[self.parsedTubeLines addObject:[self.tubeLine mutableCopy]];
} else if ([elementName isEqualToString:kNameElementName]) {
self.tubeLine.lineName = self.currentParsedStringData;
}
self.accumulatingParsedCharacterData = NO;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (self.accumulatingParsedCharacterData) {
[self.currentParsedStringData appendString:string];
}
}
No comments:
Post a Comment