Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ulquiorra

macrumors member
Original poster
Jun 17, 2009
38
0
hello all, I'm parsing an xml file and i've been trying to strip out the whitespace characters in my currentElementValue because it's messing up a couple of things.

I can see in my output window that a couple of carriage returns and tabs are present

Code:
    (gdb) po string
    Keep the arms on the side, and lift your leg.
    (gdb) po currentElementValue
    
    	
    	
    		Keep the arms on the side, and lift your leg.
    (gdb)

This is my foundCharacters function and I've been trying to use stringByTrimmingCharactersInSet unfortunately with no success.

Code:
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 
    	if(!currentElementValue) 
    		currentElementValue = [[NSMutableString alloc] initWithString:string];
    	else
    	{		
    	
    		[currentElementValue appendString:string];
    		
    		currentElementValue = [currentElementValue stringByTrimmingCharactersInSet:
    							   [NSCharacterSet newlineCharacterSet]];		
    			NSString *instructions = @"instructions";	
    		[directions setValue:string forKey:instructions];  //mm 
    		[appDelegate.directions setValue:string forKey:instructions];
    		//[appDelegate.directions setObject:string forKey:currentElementValue];
    	//	[appDelegate
    	}
    }

I've been getting this error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:'
Which is strange since my currentElementValue is a NSMutableString ..
So what's going wrong ? Does anyone have a clue or idea ?
 
Which is strange since my currentElementValue is a NSMutableString ..
Are you sure? We can't be, since we haven't seen the declaration. Just because you alloc it as NSMutableString, doesn't mean it was declared as one.

Also, why do you want to trim the whitespace out inside of foundCharacters:? Why not just do it once, inside of didEndElement:, when you have the entire string to mess with?
 
well , in my header I've put

Code:
NSMutableString *currentElementValue;

So I'm assuming i've done that correctly.

I found it easier to manipulate the string and currentElementValue in foundCharacters but to be honest it's actually more for testing purposes it makes more sense I guess to do it in didEndElement.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.