title: Objective-C nodesForXPath returns all results
body: <p>this is a follow up to a question I posted yesterday.</p>
  
  <p>Given the cars XML example posted below, I run do an xpath query, loop through the results and call "quickquery - getString" with the sub element. I would expect that with each iteration of the loop I would get a single  element inside the getString function, but I don't. Instead,  the nodesForXPath call, inside of the getString function, returns all 4 car names, instead of just the one that belongs to that sub element.</p>
  
  <pre><code>NSArray *listings = [response nodesForXPath:@"//car" error:&amp;error];
  
  //4 car elements found        
  if(listings.count &gt; 0)
  {
      for (GDataXMLElement *listingElement in listings) 
      {
          //printing listingElements description at this point reveales only one car
          [QuickQuery getString:listingElement fromXPath:@"//name"];
      }
  }
  
  //this is defined in QuickQuery class
  +(NSString *) getString:(GDataXMLElement *)element fromXPath:(NSString *)xPath
  {
      NSError *error;
      //Query the name element for the spcific car element passed in
      NSArray *result = [element nodesForXPath:xPath error:&amp;error]; /// ***THIS CALL
  
      //result.count is 4 at this stage ("BMW", "VW" ... etc)
      //out of the 4 calls made to this method, I would expect each value to come up once
      //but each time all 4 values are found.
      if(result.count &gt; 0)
      {
          GDataXMLElement *singleValue = (GDataXMLElement *) [result objectAtIndex:0];
          return singleValue.stringValue;
      }
      return nil;
  }
  
  
  &lt;cars&gt;
    &lt;car&gt;
      &lt;name&gt;VW&lt;/name&gt;
    &lt;/car&gt;
    &lt;car&gt;
      &lt;name&gt;BMW&lt;/name&gt;
    &lt;/car&gt;
    &lt;car&gt;
      &lt;name&gt;Mazda&lt;/name&gt;
    &lt;/car&gt;
    &lt;car&gt;
      &lt;name&gt;Nissan&lt;/name&gt;
    &lt;/car&gt;
  &lt;/cars&gt;
  </code></pre>
  
  <p>This question has been posted before, this is just a cleaner example and code. The title is also more specific.</p>