Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableString issue with NSXMLParser
    text
    copied!<p>I am having a heck of a time with this -- I am trying to parse an XML file and set the text in a NSMutableString variable in order to later fill in a label's text as you can see below. </p> <p>In my .h I have the following (simplified);</p> <pre><code>NSMutableString *contentsOfCurrentXMLProperty; @property (nonatomic,retain) NSMutableString *contentsOfCurrentXMLProperty; </code></pre> <p>In my .m:</p> <pre><code>-(void) parseData { NSXMLParser *parser = [[NSXMLParser alloc] initWithData:myData]; [parser setDelegate:self]; [parser parse]; [parser release]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"Title"]) { NSLog(@"FOUND TITLE!"); contentsOfCurrentXMLProperty = [NSMutableString setString:@""]; } } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementName isEqualToString:@"TITLE"]) { myLabel.text = [contentsOfCurrentXMLProperty stringByReplacingOccurrencesOfString:@"[br]" withString:@"\n"]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { [self.contentsOfCurrentXMLProperty appendString:string]; } </code></pre> <p>When I run my app, the data is downloaded and parsed correctly. I run into issues when my observer fires off the event again. The parseData method is called and I get an error that I have traced to the line that reads: "contentsOfCurrentXMLProperty = [NSMutableString setString:@""]; " </p> <p>What is the proper way to create or init a NSMutableString variable for me to use over and over? When/Where is the best place to release it? How do I essentially clear the variable so that when the observer fires off the parseData method it will again be able to set "contentsOfCurrentXMLProperty"?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload