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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:24:12+00:00 2026-05-24T05:24:12+00:00

I have a problem parsing a XML to NSArray of NSDictionary. I don’t know

  • 0

I have a problem parsing a XML to NSArray of NSDictionary. I don’t know why, but instead of the array gets 2 objects (in this case), it take 2 objects with equal data… Why?

Here’s the code:

@interface RLparseXMLToArrayOfDictionarys : NSObject <NSXMLParserDelegate> {
    NSMutableArray *arrayWithResult;
    NSMutableDictionary *tempDict;
    NSMutableString *currentString;
    NSString *groupKey;
}

@property (nonatomic, strong) NSString *groupKey;
@property (nonatomic, retain) NSMutableArray *arrayWithResult;
@property (nonatomic, retain) NSMutableDictionary *tempDict;

-(NSArray *)parseXMLWithStringToArray:(NSString *)stringWithXML withGroupKey:(NSString *)groupKeyToIgnore;

@end




@implementation RLparseXMLToArrayOfDictionarys

@synthesize groupKey;
@synthesize arrayWithResult;
@synthesize tempDict;


- (id)init
{
    self = [super init];
    if (self) {

    }

    return self;
}


-(NSArray *)parseXMLWithStringToArray:(NSString *)stringWithXML withGroupKey:(NSString *)groupKeyToIgnore{
    NSData *currentStringData = [stringWithXML dataUsingEncoding:NSUTF8StringEncoding];
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:currentStringData];
    [parser setDelegate:self];

    // Set Parser Options
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];

    //key to ignore
    self.groupKey = groupKeyToIgnore;

    if (!arrayWithResult) {
        arrayWithResult = [[NSMutableArray alloc] init];
    }

    if (!tempDict) {
        tempDict = [[NSMutableDictionary alloc] init];
    }

    [parser parse];

    NSLog(@"return: %@", arrayWithResult);

    return arrayWithResult;
}


#pragma mark -
#pragma mark XML methods

- (void)parserDidStartDocument:(NSXMLParser *)parser
{

}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{

}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if(!currentString){
        currentString = [[NSMutableString alloc] init];
    }

    [currentString appendString:string];
}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    NSString *currentStringNoWhiteSpace = [currentString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if ([elementName isEqualToString:groupKey]){
        [arrayWithResult addObject:tempDict];
//      [tempDict removeObjectsForKeys:[tempDict allKeys]];
    }

    else if (currentStringNoWhiteSpace != nil)
        [tempDict setValue:currentStringNoWhiteSpace forKey:elementName];

    currentStringNoWhiteSpace = nil;
    currentString = nil;
}


- (void)parserDidEndDocument:(NSXMLParser *)parser {

}

@end
  • 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-24T05:24:13+00:00Added an answer on May 24, 2026 at 5:24 am

    Done!

    Replace [tempDict removeObjectsForKeys:[tempDict allKeys]];
    with tempDict = [[NSMutableDictionary alloc] init];

    🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in parsing XML containing gsm packets through my .Net application.I want
I have a problem parsing an xml, actually transforming it. The error I get
I have problem with parsing XML. I parsed data of cities, Amsterdam & Den
i have a problem while building and running an iphone application.Im using xml parsing
OK suppose I'm parsing some XML (the problem exists while reading any language but
I have done one program in android using xml parsing but there is an
I got a problem regarding parsing XML data. I have divided my program into
I am parsing an XML but having some problem regrading its attribute. I wan
I have a process that is parsing an XML file. This is occuring in
I have a problem with parsing xml by an android, a document that is

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.