title: how to parse xml for ios development
body: <p>So I know how to parse some XML structures but I am currently trying to parse this specific xml structure thats a bit different to what I am used to.</p>
  
  <p>normally I would parse something like</p>
  
  <pre><code>&lt;xml&gt;
    &lt;data&gt;
      &lt;name&gt;Forrest&lt;/name&gt;
      &lt;age&gt;25&lt;/name&gt;
      &lt;username&gt;forrestgrant&lt;/username&gt;
    &lt;/data&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>But now I'm working with some xml like so..</p>
  
  <pre><code>&lt;xml&gt;
    &lt;data name="Forrest" age="25" username="forrestgrant" /&gt;
    &lt;other value="6" /&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>how do I access those variables when they are structured like this?
  This is how I would normally approach this task, which is baised of searching for the title tags  and getting the data from each one.. however I am now trying to figure out how to parse this other style of xml.</p>
  
  <pre><code>- (void)startTheParsingProcess:(NSData *)parserData
  {
      [myDataArray release]; // clears array for next time it is used.
      myDataArray = [[NSMutableArray alloc] init]; //initalizes the array
  
      NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 
  
      [parser setDelegate:self];
      [parser parse]; //Starts the event-driven parsing operation.
      [parser release];
  }
  
  - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
  {
      if ([elementName isEqual:@"item"]) {
          // NSLog(@"Found title!");
          itemString = [[NSMutableString alloc] init];
      }
  }
  
  - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
  {
      [itemString appendString:string];
  }
  
  - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
  {
      if ([elementName isEqual:@"item"]) {
          //NSLog(@"ended title: %@", itemString);
          [myDataArray addObject:itemString]; //this is where i pass the values over to my array.
  
          [itemString release];
          itemString = nil;
      }
  }
  
  - (void)parserDidEndDocument:(NSXMLParser *)parser
  {
      // Passes myDataArray to the method that will sort and display the array into a uitableview.
      [self startSortingTheArray:myDataArray];
  }
  </code></pre>
  
  <p>any help would be greatly appreciated..</p>