title: Creating an array content with dictionaries using NSXMLParsing in iOS
body: <p>Afternoon overflowers,</p>
  
  <p>In my code, I'm trying to parse and SOAP response that is in NSData format. With that data, using NSXMLParse, I'm trying to create an array of dictionaries. The problem is, anytime I add my new dictionary to the array, it replaces the old dictionary object contents with the currently added one. For instance, at the end of the parse, I have 7 dictionaries with the same content in my array. Here is the code to show what I have done;</p>
  
  <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
      NSLog(@"Received the SOAP data.");
  
      if (!itemArray) {
          itemArray = [[NSMutableArray alloc] init];
      }
      else {
          itemArray = nil;
          itemArray = [[NSMutableArray alloc] init];
      }
  
      if (!itemDictionary) {
          itemDictionary = [[NSMutableDictionary alloc] init];
      }
      else {
          itemDictionary = nil;
          itemDictionary = [[NSMutableDictionary alloc] init];
      }
  
      parser = [[NSXMLParser alloc] initWithData:webData];
      [parser setDelegate:self];
      [parser parse];
  }
  
  - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
      NSLog(@"Started Element %@", elementName);
      element = [NSMutableString string];
  }
  
  - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
      if(element == nil) {
          element = [[NSMutableString alloc] init];
      }
  
      [element appendString:string];
  }
  
  - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
      NSLog(@"Found an element named: %@ with a value of: %@", elementName, element);
  
      if (![elementName isEqualToString:@"item"]) {
          [itemDictionary setValue:element forKey:elementName];
      }
      else if ([elementName isEqualToString:@"item"]) {
          if (itemDictionary) {
              [itemArray addObject:itemDictionary];
  
              [itemDictionary removeAllObjects];
          }
      }
  }
  </code></pre>
  
  <p>Thank you in advance.
  Regards</p>