Re: referencing XML Data
Re: referencing XML Data
- Subject: Re: referencing XML Data
- From: Amy Heavey <email@hidden>
- Date: Tue, 16 Sep 2008 21:15:54 +0100
I've just tried this again, I just changed the start:
void import( NSArray *array ) {
and it is all called by:
import(custNodes);
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];
but I still get 3 errors,
I'm using XCode 2.4.1 and wanting this to work on 10.4 systems.
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];
//if ( [customerArray count]) {
//for (NSXMLNode *customerNode in customerArray){
NSLog(@"First name = %@", 0);
customerNode=[custNodes objectAtIndex:0];
NSArray *firstNameArray = [customerNode nodesForXPath:@".//
first_name" error:nil];
//if ([firstNameArray count]) {
NSString *firstNameString = [[firstNameArray objectAtIndex:0]
stringValue];
NSLog(@"First name = %@", firstNameString);
//}
//}
//}
}
}
but I get
2008-09-16 21:12:22.044 ag01[8400] First name = (null)
2008-09-16 21:12:22.055 ag01[8400] First name = Willow
2008-09-16 21:12:22.458 ag01[8400] First name = (null)
2008-09-16 21:12:22.469 ag01[8400] First name = Willow
2008-09-16 21:12:22.730 ag01[8400] First name = (null)
2008-09-16 21:12:22.741 ag01[8400] First name = Willow
2008-09-16 21:12:22.931 ag01[8400] First name = (null)
2008-09-16 21:12:22.937 ag01[8400] First name = Willow
2008-09-16 21:12:23.338 ag01[8400] First name = (null)
2008-09-16 21:12:23.338 ag01[8400] First name = Willow
2008-09-16 21:12:23.573 ag01[8400] First name = (null)
2008-09-16 21:12:23.587 ag01[8400] First name = Willow
2008-09-16 21:12:23.845 ag01[8400] First name = (null)
2008-09-16 21:12:23.854 ag01[8400] First name = Willow
2008-09-16 21:12:24.056 ag01[8400] First name = (null)
2008-09-16 21:12:24.064 ag01[8400] First name = Willow
2008-09-16 21:12:24.268 ag01[8400] First name = (null)
........
I assume it's to do with customerNode=[custNodes objectAtIndex:0];
but I can't work out what to use instead of objectAtIndex:0
Thank you for all your time,
Many Thanks
Amy
On 16 Sep 2008, at 21:02, Nathan Kinsinger wrote:
On Sep 16, 2008, at 1:24 PM, Amy Heavey wrote:
if ([firstNameArray count]) {
NSString *firstNameString = [[firstNameArray objectAtIndex:0]
stringValue];
// do something with the first name string
NSLog(@"First name = %@", firstNameString);
}
// get other strings
// do something with the other strings
}
}
Many Thanks
Amy
I don't see any problem with your for loop statement and compiling
the code works with no errors (after fixing my syntax error). What
version of XCode are you using?
Here's my test (written in XCode :-)
- (void)testXML
{
NSXMLDocument *custdoc = [[NSXMLDocument alloc] initWithData:
[NSData dataWithContentsOfFile:@"/Users/nathan/Desktop/xml testing/
customer.xml"] options:0 error:nil];
NSArray *customerArray = [custdoc nodesForXPath:@".//customer"
error:nil];
if ([customerArray count]) {
for (NSXMLNode *customerNode in customerArray) {
NSArray *firstNameArray = [customerNode nodesForXPath:@".//
first_name" error:nil];
if ([firstNameArray count]) {
NSString *firstNameString = [[firstNameArray objectAtIndex:0]
stringValue];
NSLog(@"First name = %@", firstNameString);
}
}
}
}
using the data from your first email as the xml file I get:
2008-09-16 14:00:25.137 testStrings[17811:10b] First name = Willow
2008-09-16 14:00:25.159 testStrings[17811:10b] First name = L****
--Nathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden