On Sep 16, 2008, at 2:15 PM, Amy Heavey wrote:
I've just tried this again, I just changed the start:

void import( NSArray *array ) {

and it is all called by:

import(custNodes);

I assume that means you did something like:

        NSArray *custNodes = [custdoc nodesForXPath:@".//customer" error:nil];


so I beleive this line is uneccessary:
NSXMLDocument *custdoc = [[NSXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:@"/Users/nathan/Desktop/xml testing/ customer.xml"] options:0 error:nil];

Yes, I just needed that to get the XML file for testing.

        
but I still get 3 errors,

I'm using XCode 2.4.1 and wanting this to work on 10.4 systems.

Sorry, the for-in loop I was using is for 10.5. NSEnumerator (as you are using below) is correct for your case.


I've managed to get this to nearly work:

void import( NSArray *array ) {
        
        NSEnumerator *enumerator = [array objectEnumerator];
        id obj;
        
    while ( obj = [enumerator nextObject] ) {
                
                //printf( "Customer: %s\n", [[obj description] cString] );
                
NSArray *customerArray = [custdoc nodesForXPath:@".//customer" error:nil];

I think your array already has the .//customer data in it, don't need to get it again.

                 //if ( [customerArray count]) {
                        //for (NSXMLNode *customerNode in customerArray){
                NSLog(@"First name = %@", 0);

Do you really want to print 0 here?

                customerNode=[custNodes objectAtIndex:0];

This will keep getting the first customer out of the customerArray.

        
NSArray *firstNameArray = [customerNode nodesForXPath:@".// first_name" error:nil];
                         //if ([firstNameArray count]) {
NSString *firstNameString = [[firstNameArray objectAtIndex:0] stringValue];
                NSLog(@"First name = %@", firstNameString);
                //}
                //}
                //}

        }
}



As far as your loop goes, obj is the item in each iteration of the loop, so use that to get the current customer item from the array.

So, getting rid of some other stuff that leaves:

void import( NSArray *array ) {
        NSEnumerator *enumerator = [array objectEnumerator];
        id obj;
        
        while ( obj = [enumerator nextObject] ) {
NSArray *firstNameArray = [obj nodesForXPath:@".//first_name" error:nil]; NSString *firstNameString = [[firstNameArray objectAtIndex:0] stringValue];
                NSLog(@"First name = %@", firstNameString);
        }
}

This assumes you already did the .//customer XPath call and passed that in as the array.

--Nathan

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to