I have a problem when parsing an XML feed. There are approximately 15 child nodes per parent node. Currently I am parsing all nodes using stringbytrimmingchartersinset: then NSCharacterset whitespaceandnewline characterset. Like so:
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
This works great for all but one of the nodes. For this node I want the text to come through as is. I've tried setting up an if statement to treat this particular node differently than the others so I updated to the following.
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([testingString isEqualToString:@"AdoptionSummary"]) {
[currentElementValue appendString:string]; //This keeps breaking
}
else {
currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
however I'm getting an error.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:'
The error only occurs if I use a combination of stringbytrimmingchartersinset and appendString. However if I use either stringbytrimmingchartersinset or appendString on there own it parses without error. currentElementValue
is an NSMutableString so why is this error being thrown?
I've tried looking at this NSMutableString appendString generates SIGABRT Error, and this error : 'Attempt to mutate immutable object with appendString:' -- but to no avail.
I would like just 'AdoptionSummary" to append 'as is' while the other 14 are trimmed. What am I doing wrong? Any suggestions?
Thanks!