Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4059058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:09:32+00:00 2026-05-20T15:09:32+00:00

Hey, I have to parse XML in my iOS app. I took Apple’s SeismicXML

  • 0

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.

These are my parser methodes:

    - (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:@""];
}

}

- (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] >= 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;

}

- (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];
}

}

Everything works great, the XML Data comes correctly. The parser parses everything as it should.
The problem is in the parser didEndElement methode.

 else if ([elementName isEqualToString:kTitleElementName]) {
    self.currentPhotoObject.titleText = self.currentParsedCharacterData;
} 

When I get “self.currentPhotoObject.titleText” via NSLog, I get the right parsed Data. But then:

else if ([elementName isEqualToString:kAuthorElementName]) {
    self.currentPhotoObject.author = self.currentParsedCharacterData;

}

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.

I have no idea why .titleText e.g. is changed when the parser sets .author.

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 !

Greets Sebastian

ps: My properties in the .m file:

@interface ParseOperation () <NSXMLParserDelegate>
@property (nonatomic, retain) Photo *currentPhotoObject;
@property (nonatomic, retain) NSMutableArray *currentParseBatch;
@property (nonatomic, retain) NSMutableString *currentParsedCharacterData;
@end

@implementation ParseOperation

@synthesize photoData, currentPhotoObject, currentParsedCharacterData, currentParseBatch;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:09:33+00:00Added an answer on May 20, 2026 at 3:09 pm

    It’s because you assign same NSMutableString instance to all this properties.

    1) Declare author, titleText, locationText properties as copy to avoid this in future.

    2) Make a copy each time you want to return value of NSMutableString or assign it to something

    self.currentPhotoObject.titleText = [[self.currentParsedCharacterData copy] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have an XML file I need to parse, but only for
Hey I have a really annoying IE7 bug that I am trying to work
Hey I have this code but it doesn't work because it is expecting a
Hey I have an XML file and I would like to navigate to a
hey guys, we have a loop that: 1.Loops over several thousand xml files. Altogether
Hey I have used parsers in the past but never in an ARC environment.
Hey, I have an iphone program that has a parser that parses some XML
Hey guys. I'm trying to parse xml file in order to extract some data
Hey. I want to have a config.xml file for settings in a Python web
Hey I have an array with numbers in it. Now I want to divide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.