• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: referencing XML Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: referencing XML Data


  • Subject: Re: referencing XML Data
  • From: Nathan Kinsinger <email@hidden>
  • Date: Tue, 16 Sep 2008 14:02:15 -0600


On Sep 16, 2008, at 1:24 PM, Amy Heavey wrote:

Thanks,

I've been messing about with code all over the place, gone a little blind I think,

however, I now get 2 errors on this line:

1 - nested functions are disabled, use -fnested-functions to renable
2 - syntax error before in


NSArray *customerArray = [custdoc nodesForXPath:@".//customer" error:nil];
if ([customerArray count]) {
for (NSXMLNode *customerNode in customerArray) {
NSArray *firstNameArray = [[customerNode nodesForXPath:@".// first_name" error:nil];

This line has two [ at the beginning and only needs one (that's my error from my earlier email, the problem with typing code into mail)


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


  • Follow-Ups:
    • Re: referencing XML Data
      • From: Amy Heavey <email@hidden>
References: 
 >referencing XML Data (From: Amy Heavey <email@hidden>)
 >Re: referencing XML Data (From: Nathan Kinsinger <email@hidden>)
 >Re: referencing XML Data (From: Amy Heavey <email@hidden>)
 >Re: referencing XML Data (From: "Sherm Pendley" <email@hidden>)
 >Re: referencing XML Data (From: Amy Heavey <email@hidden>)

  • Prev by Date: Re: How to uniquely determine MD5-sum of a dict?
  • Next by Date: Re: referencing XML Data
  • Previous by thread: Re: referencing XML Data
  • Next by thread: Re: referencing XML Data
  • Index(es):
    • Date
    • Thread