title: xml element inserting error with Objective-C garbage collection turned on
body: <p>The following piece of code worked fine if garbage collection was not turned on in the project properties option.  But with GC turned on, this is the error message:</p>
  
  <p>"<em>*</em> Assertion failure in -[NSXMLFidelityElement insertChild:atIndex:], /SourceCache/Foundation/Foundation-751.53/XML.subproj/XMLTypes.subproj/NSXMLElement.m:823"
  "Cannot add a child that has a parent; detach or copy first"</p>
  
  <p>Any suggestion?</p>
  
  <pre><code> -(void)insertXmlRecord
  {
      //xmlDoc is an iVar
      NSXMLElement *nodeToAdd = [[NSXMLElement alloc] initWithXMLString:[self readOnScreenSetAttrib] error:nil];  
      NSError *err=nil;
      NSXMLElement *thisName;
      NSArray *nodes = [xmlDoc nodesForXPath:@"./dream" error:&amp;err];
      NSLog(@"insertXMLRecord xmldoc %@", xmlDoc);    
      if ([nodes count] &gt; 0 ) 
      {
          thisName = [nodes objectAtIndex:0];
          NSLog(@"insertXMLRecord: thisname: %@", thisName);
          NSLog(@"insertXMLRecord: nodeToAdd: %@", nodeToAdd);
          [thisName addChild:nodeToAdd];
      }
      //NSLog(@"insertXMLRecord");
  }
  </code></pre>