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 6013317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:31:52+00:00 2026-05-23T02:31:52+00:00

I’m using NSXMLParser to parse an XML file. I’m doing this several times in

  • 0

I’m using NSXMLParser to parse an XML file. I’m doing this several times in my app for different purposes. I have one which parses annotations for a store locator, one that parses al the movies from a certain YouTube channel and the last one parses a self made XML file.

All parsers work great except the last one. For some kind of reason it parses i.e. the first node good, but then overwrites it.

Here is my parser code:

    //Standard function parser: reading open tag
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
      namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
        attributes:(NSDictionary *)attributeDict{ 
        currentElement = [elementName copy];
        if ([elementName isEqualToString:@"item"]) {
            xmlArray = [[NSMutableDictionary alloc] init];
        }

    }


    //Standard function parser: reading string
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
        if ([currentElement isEqualToString:@"created_time"]){
            [xmlArray setObject:string forKey:currentElement]; 
            NSLog(@"test 1 %@", string);}
    }    


    //Standard function parser: reading close tag
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
      namespaceURI:(NSString *)namespaceURI
     qualifiedName:(NSString *)qName{ 
        if ([elementName isEqualToString:@"item"]) {
            Post *newPost = [[Post alloc] init];
            NSLog(@"test %@", xmlArray );
            newPost.created_time = [xmlArray objectForKey:@"created_time"];
            [containerArray addObject:newPost];
            [xmlArray release];


 }
}  

The XML looks like this:

<?xml version="1.0" encoding="UTF-8" ?> 
<items>
<item> 
<created_time>test</created_time> 
<message>blabla</message> 
<picture>http://www.trentshow.com/images/tada.jpg</picture> 
</item>
</items>

And the log outputs the following:

2011-06-10 10:43:24.446 TabbedCalculation[1502:207] test 1 test
2011-06-10 10:43:24.448 TabbedCalculation[1502:207] test 1  
2011-06-10 10:43:24.449 TabbedCalculation[1502:207] test 1 
2011-06-10 10:43:24.450 TabbedCalculation[1502:207] test {
    "created_time" = "\n";
}

I’m not getting why the parser loops 3 times over the created_time node. Any help would be great!

  • 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-23T02:31:53+00:00Added an answer on May 23, 2026 at 2:31 am

    Try by following solution — should work.
    foundCharacters can be called for multiple time for each key value — basically you should append all found character list.

       - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
                if ([currentElement isEqualToString:@"created_time"]){
                    NSString *valueKey = [xmlArray ValueForKey:forKey:currentElement];
                    if(nil != valueKey) 
                    {
                       valueKey = [valueKey stringByAppendingString:string];
                    }else
                    {
                       valueKey = string;
                    }
                    [xmlArray setObject:valueKey forKey:currentElement]; 
                    NSLog(@"test 1 %@", string);}
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.