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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:51:25+00:00 2026-06-14T13:51:25+00:00

I am using NSXML to parse out an XML document and add the results

  • 0

I am using NSXML to parse out an XML document and add the results to an array of objects. The array has the correct number of objects, but they are full of data from the last object.(i.e. the object at index 0 has the same data as at index 3). I am getting good data back from my server.

//set up my objects and arrays higher in my structure
SignatureResult *currentSignatureResult = [[SignatureResult alloc]init];
Document *currentDoc = [[Document alloc]init];
Role *currentRole = [[Role alloc]init];             
NSMutableArray *roleArray = [[NSMutableArray alloc] init];
NSMutableArray *doclistArray2 = [[NSMutableArray alloc] init];


.....there is more parsing up here
//role is defined as an NSXML Element
for (role in [roleList childrenNamed:@"role"]){

    NSString *firstName =[role valueWithPath:@"firstName"];
    NSString *lastName = [role valueWithPath:@"lastName"];
    currentRole.name = [NSString stringWithFormat:@"%@ %@",firstName, lastName];



    for (documentList2 in [role childrenNamed:@"documentList"])
       {
        SMXMLElement *document = [documentList2 childNamed:@"document"];
        currentDoc.name = [document attributeNamed:@"name"];
        [doclistArray2 addObject:currentDoc];
        }
    currentRole.documentList = doclistArray2;
    [roleArray addObject:currentRole];
    ///I've logged currentRole.name here and it shows the right information

}//end of second for statemnt

currentSignatureResult.roleList = roleArray;
}
///when I log my array here, it has the correct number of objects, but each is full of
///data from the last object I parsed
  • 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-06-14T13:51:26+00:00Added an answer on June 14, 2026 at 1:51 pm

    The cause is that the addObjects: retains for your currentRole object and not creates a copy from that. You can create your new currentRole object inside of the for or you can create a copy from that and add it to the array.
    I recommend the following:

    for (role in [roleList childrenNamed:@"role"]){
        Role *currentRole = [[Role alloc] init];
        NSString *firstName =[role valueWithPath:@"firstName"];
        NSString *lastName = [role valueWithPath:@"lastName"];
        currentRole.name = [NSString stringWithFormat:@"%@ %@",firstName, lastName];
    
    
    
        for (documentList2 in [role childrenNamed:@"documentList"])
           {
            SMXMLElement *document = [documentList2 childNamed:@"document"];
            currentDoc.name = [document attributeNamed:@"name"];
            [doclistArray2 addObject:currentDoc];
            }
        currentRole.documentList = doclistArray2;
        [roleArray addObject:currentRole];
        ///I've logged currentRole.name here and it shows the right information
        [currentRole release];
    
    }//end of second for statemnt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse XML from a .NET WCF Webservice using NSXML Parser.
I am trying to parse an XML file using NSXMLParser, but the method [parser
i want to parse google weather API using NSXML so please give me some
Hello all I'm using NSXMLParser to parse some xml data. I'm using this data
I am using retailligence barcode api and using nsxml parser method to parse the
How do you extract attributes from XML using NSXML parser?? Heres my xml: <item>
I am using NSXMLParser to parse a remote XML file to display information in
I need to parse an HTML document using NSXmlParser.As you know there are three
I'm using NSXMLParser to parse an rss feed. But I'm getting some strange behavior
I am using NSXMLParser to parse this XML: http://itunes.apple.com/gb/rss/topsongs/limit=50/explicit=true/xml . I am trying to

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.