Here is what I am trying to do. Please help me understand what I'm doing wrong!
I have an XML file that I want to parse. I want to be able to parse this somewhat dynamically, given that we'll be using it for various archives of the same format. Given this idea, I want to put each tag into an NSDictionary.
Since I'm parsing XML, I need to build the results, which I am doing like this:
Code:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[results appendString:string];
}
When the element ends, I have an if-else chain that assigns results to the appropriate NSDictionary:
Code:
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if (currentProperty) {
//set the idTag for the entry and appent the idTag to the array of Entries.
if ([currentProperty isEqualToString: @"Thumb"]) {
[thumbURL setObject:results forKey:idTag];
[results setString:@""];
} else if ([currentProperty isEqualToString: @"Path"]) {
[pathURL setObject:results forKey:idTag];
[results setString:@""];
} else if ([currentProperty isEqualToString: @"Transcription"]) {
[transcription setObject:results forKey:idTag];
[results setString:@""];
} else if ([currentProperty isEqualToString: @"Meta"]) {
//Haven't written this yet.
[results setString: @"" ];
} else if ([currentProperty isEqualToString: @"Context"]) {
[context setObject:results forKey:idTag];
[results setString:@""];
} else if ([currentProperty isEqualToString: @"Inferences"]) {
[inferences setObject:results forKey:idTag];
[results setString:@""];
}
}
if ([currentProperty isEqualToString:@"Entry"]) {
[meta setObject:individualMeta forKey:idTag];
[individualMeta removeAllObjects];
}
//reset current properties
currentProperty = nil;
attributeValue = nil;
}
The problem seems to be that when I set my dictionary entries, it's maintaining a persistent connection to 'results'. I tested this theory by putting:
Code:
NSLog(@"transcription %@", [transcription objectForKey:idTag]);
both before and after the
Code:
[results setString:@""];
before that line of code, it returns what I want, after, it returns nothing.
I have a sneaking suspicion that I'm just overlooking some detail, but any help would be greatly appreciated. Let me know if you need any other information about my code.