title: NSArray to Core Data items
body: <p>I have an method that reads an xml file and stores the xml nodes at a certain XPath-path in an NSArray called *nodes. What I want to do is take each one of the items in the array and add it to a core data entity called Category with the attribute of "name". </p>
  
  <p>I have tried a number of different ways of creating the entity but I'm not sure about the correct way to do this effectively. This is the code used to create the NSArray, any ideas on how to implement this? (ignore the NSError, I will fix this in the final version)</p>
  
  <pre><code>- (IBAction)readCategories:(id)sender
  </code></pre>
  
  <p>{</p>
  
  <pre><code>NSString *xmlString = [resultView string];
  
  NSData *xmlData = [xmlString dataUsingEncoding: NSASCIIStringEncoding];
  
  NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithData:xmlData options:nil error:nil];
  
  //XPath
  
  NSError *err=nil;
  
  NSArray *nodes = [xmlDoc nodesForXPath:@"//member[name='description']/value/string" error:&amp;err];
  </code></pre>
  
  <p>}</p>
  
  <p>EDIT - My loop code</p>
  
  <pre><code>NSArray *nodes = [xmlDoc nodesForXPath:@"//member[name='description']/value/string" error:&amp;err];
  int arrayCount = [nodes count];
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSXMLElement *categoryEl;
  NSString *new = [catArrayController newObject];
  int i;
  for (i = 0; i &lt; arrayCount; i++)
  {
      [categoryEl = [nodes objectAtIndex:i]];
      [new setValue:[categoryEl stringValue] forKey:@"name"];
      [catArrayController addObject:new];
  }
  [pool release];
  </code></pre>