Note that there are some explanatory texts on larger screens.

plurals
  1. PONSXMLParser problem - SeismicXML Sample
    primarykey
    data
    text
    <p>Hey, I have to parse XML in my iOS app. I took Apple's SeismicXML Sample as my base, but I'm experiencing a really strange behaviour.</p> <p>These are my parser methodes:</p> <pre><code> - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:kEntryElementName]) { Photo *photo = [[Photo alloc] init]; self.currentPhotoObject = photo; [photo release]; } else if ([elementName isEqualToString:kTitleElementName] || [elementName isEqualToString:kLocationElementName] || [elementName isEqualToString:kAuthorElementName]) { accumulatingParsedCharacterData = YES; [currentParsedCharacterData setString:@""]; } </code></pre> <p>}</p> <pre><code>- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementName isEqualToString:kEntryElementName]) { NSLog(@"Did End - Titel:%@", self.currentPhotoObject.titleText); NSLog(@"Did End - Location:%@", self.currentPhotoObject.locationText); NSLog(@"Did End - Author:%@", self.currentPhotoObject.author); [self.currentParseBatch addObject:self.currentPhotoObject]; parsedPhotosCounter++; if ([self.currentParseBatch count] &gt;= kMaximumNumberOfPhotosToParse) { [self performSelectorOnMainThread:@selector(addPhotosToList:) withObject:self.currentParseBatch waitUntilDone:NO]; self.currentParseBatch = [NSMutableArray array]; } } else if ([elementName isEqualToString:kTitleElementName]) { self.currentPhotoObject.titleText = self.currentParsedCharacterData; } else if ([elementName isEqualToString:kAuthorElementName]) { self.currentPhotoObject.author = self.currentParsedCharacterData; } else if ([elementName isEqualToString:kLocationElementName]) { self.currentPhotoObject.locationText = self.currentParsedCharacterData; } accumulatingParsedCharacterData = NO; </code></pre> <p>}</p> <pre><code>- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if (accumulatingParsedCharacterData) { // If the current element is one whose content we care about, append 'string' // to the property that holds the content of the current element. // [self.currentParsedCharacterData appendString:string]; } </code></pre> <p>}</p> <p>Everything works great, the XML Data comes correctly. The parser parses everything as it should. The problem is in the parser didEndElement methode.</p> <pre><code> else if ([elementName isEqualToString:kTitleElementName]) { self.currentPhotoObject.titleText = self.currentParsedCharacterData; } </code></pre> <p>When I get "self.currentPhotoObject.titleText" via NSLog, I get the right parsed Data. But then:</p> <pre><code>else if ([elementName isEqualToString:kAuthorElementName]) { self.currentPhotoObject.author = self.currentParsedCharacterData; } </code></pre> <p>When I get the NSLog of "self.currentPhotoObject.titleText" and from "self.currentPhotoObject.author" here, both give me the author. In the third parsed methode it is the same. All three properties (titleText, author and locationText) are the locationText.</p> <p>I have no idea why .titleText e.g. is changed when the parser sets .author.</p> <p>I have doublechecked everything at least 10 times and compared it to the SeismicXML sample but I can't find the problem. Please help me. I'm thankfull for every hint !</p> <p>Greets Sebastian</p> <p>ps: My properties in the .m file:</p> <pre><code>@interface ParseOperation () &lt;NSXMLParserDelegate&gt; @property (nonatomic, retain) Photo *currentPhotoObject; @property (nonatomic, retain) NSMutableArray *currentParseBatch; @property (nonatomic, retain) NSMutableString *currentParsedCharacterData; @end @implementation ParseOperation @synthesize photoData, currentPhotoObject, currentParsedCharacterData, currentParseBatch; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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