title: NSXML XML Parsing issue iOS
body: <p>I know that there are plenty of questions that have been asked and answered and non of them pertain to my problem.</p>
  
  <p>I am posting XML to a server and I get a response back. My problem is getting a specified key back from the response.</p>
  
  <p>I am trying to list all Genders e.g Male, Female and their id's however when parsing the XML into text with NSXML I only get back the Female and ID 2 and I do not get back Male?</p>
  
  <p>I have researched and tried to fix this issue but to no avail.</p>
  
  <p>here is my code:</p>
  
  <pre><code>- (void)getGender {
  
      NSString *soapMessage = [NSString stringWithFormat:
                               @"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
                               "&lt;soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:app=\"http://app.ws.api.bells.wigroup.com/\"&gt;"
                               "&lt;soap:Header/&gt;\n"
                               "&lt;soap:Body&gt;\n"
                               "&lt;app:getAllGenders&gt;\n"
                               "&lt;request&gt;\n"
                               "&lt;apiCredentials&gt;\n"
                               "&lt;apiId&gt;IPHONE_APP&lt;/apiId&gt;\n"
                               "&lt;sha1Password&gt;8656cafcd71cbbfe773a0fdb6c422666a80e5b8f&lt;/sha1Password&gt;\n"
                               "&lt;/apiCredentials&gt;\n"
                               "&lt;request&gt;\n"
                               "&lt;/request&gt;\n"
                               "&lt;/request&gt;\n"
                               "&lt;/app:getAllGenders&gt;\n"
                               "&lt;/soap:Body&gt;\n"
                               "&lt;/soap:Envelope&gt;\n"
                               ];
      NSLog(@"Message%@",soapMessage);
  
      NSURL *url = [NSURL URLWithString:@"http://qa.wigroup.co:8080/bells/AppWS"];
      NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
      NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
  
      [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
      //[theRequest addValue: @"http://" forHTTPHeaderField:@"SOAPAction"];
      [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
      [theRequest setHTTPMethod:@"POST"];
      [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  
      NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  
      if( theConnection )
      {
  
          NSURLResponse *response;
          NSError *error;
  
          NSData *urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&amp;response error:&amp;error];
          NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
          NSLog(@"Login response XML:%@",str);
  
  
          // create and init NSXMLParser object
          XmlArrayParser *parser = [[XmlArrayParser alloc] initWithData:urlData];
          parser.rowElementName = @"return";
          parser.elementNames = [NSArray arrayWithObjects:@"response", @"responseCode", @"responseDesc", @"gendersList", nil];
          parser.attributeNames = [NSArray arrayWithObjects:@"id", @"gender", nil];
  
          if ([parser.rowElementName isEqualToString:@"responseCode"] &amp;&amp; _flag)
          {
              //read the value here
               NSLog(@"flagging");
          }
  
          // parsing...
          BOOL success = [parser parse];
  
          // test the result
          if (success)
          {
              NSMutableArray *loginAuth = [parser items];
  
              //        self.textView.text = [NSString stringWithFormat:
              //        @"This is an array of dictionaries, one dictionary for each user:\n\n%@",
              //        [users description]];
  
             // NSDictionary *eventLocation = [NSDictionary dictionaryWithObjectsAndKeys:@"response", nil];
  
              NSDictionary *loginResponse = [loginAuth objectAtIndex:0];         // this retrieves the first user
              NSString *userResponse = loginResponse[@"gendersList"];           // this retrieves that user's username in Xcode 4.5 and greater
  
              NSString *userRes = [loginResponse objectForKey:@"id"];
  
              NSString *test = [loginAuth description];
  
              NSLog(@"Returned Code loginResponse %@",loginResponse);
              NSLog(@"Returned Code userResponse %@ %@",userResponse, userRes);
              NSLog(@"Returned Code test %@",test);
  
              NSMutableArray *array=[[NSMutableArray alloc]initWithCapacity:10];
  
              for (NSDictionary *defineXMLData in loginAuth) {
  
                  NSNumber * responseCode = [defineXMLData objectForKey:@"responseCode"];
                  NSArray * responseDEsc = [defineXMLData objectForKey:@"responseDesc"];
                  NSArray * genderList = [defineXMLData objectForKey:@"gendersList"];
                 // NSArray * gender = [defineJsonData objectForKey:@"gender"];
  
                  NSLog(@"Genders%@", genderList);
  
                  [array addObject: responseCode];
                  [array addObject: responseDEsc];
                  [array addObject: genderList];
                  //[array addObject: gender];
                  // [array addObject: vouchersUser];
              }
  
              label.numberOfLines = 2000; // for example
              label.lineBreakMode = NSLineBreakByClipping;
              NSString *output=[array componentsJoinedByString:@","];
              label.text = [NSString stringWithFormat:@"XML Result: %@ ",output];
  
              [SVProgressHUD dismiss];
  
              //            [[[UIAlertView alloc] initWithTitle:nil
              //                                        message:[NSString stringWithFormat:@"No errors - user count : %i", [[parser items] count]]
              //                                       delegate:nil
              //                              cancelButtonTitle:@"OK"
              //                              otherButtonTitles:nil] show];
  
          }
          else
          {
              NSLog(@"Error parsing document!");
  
              //            [[[UIAlertView alloc] initWithTitle:nil
              //                                        message:@"Error parsing document!"
              //                                       delegate:nil
              //                              cancelButtonTitle:@"OK"
              //                              otherButtonTitles:nil] show];
          }
  
      }
      else
      {
          NSLog(@"theConnection is NULL");
      }
  
      NSLog(@"test");
  
  }
  </code></pre>
  
  <p>And the XML I get back from my nslog:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;S:Body&gt;
        &lt;ns2:getAllGendersResponse xmlns:ns2="http://app.ws.api.bells.wigroup.com/"&gt;
           &lt;return&gt;
              &lt;responseCode&gt;-1&lt;/responseCode&gt;
              &lt;responseDesc&gt;Success&lt;/responseDesc&gt;
              &lt;response&gt;
                 &lt;responseCode&gt;-1&lt;/responseCode&gt;
                 &lt;responseDesc&gt;Success&lt;/responseDesc&gt;
                 &lt;gendersList&gt;
                    &lt;gender&gt;Male&lt;/gender&gt;
                    &lt;id&gt;1&lt;/id&gt;
                 &lt;/gendersList&gt;
                 &lt;gendersList&gt;
                    &lt;gender&gt;Female&lt;/gender&gt;
                    &lt;id&gt;2&lt;/id&gt;
                 &lt;/gendersList&gt;
              &lt;/response&gt;
  </code></pre>
  
  <p>Is only parsing:</p>
  
  <pre><code>{
  gendersList = Female2;
  responseCode = "-1";
  responseDesc = Success;
  }
  </code></pre>