Trying to capture XML data and convert to a String...
Trying to capture XML data and convert to a String...
- Subject: Trying to capture XML data and convert to a String...
- From: R <email@hidden>
- Date: Wed, 18 Aug 2010 13:11:28 -0600
I'm new and in the process of learning Objective-C and Cocoa.
I want to take some raw XML data, isolate, and convert to a string. I seem to be able to capture the data I want, but cannot seem to get into a string format. Actually, I will want in a NSMutableString format… but am keeping things simple for now.
Here is an excerpt of my code:
The problem is at the end of the code below…. the string findAlerts is empty. The NSXMLElement specificAlert prints correctly.
Thanks for your thoughts and patience….
R
Note: Previous initialization:
NSXMLDocument *gameStatusXML;
NSArray *myGames;
@implementation ScoreEngine
-(NSData *)loadData{
NSLog(@"loadGameData executed");
NSString *urlString=[NSString stringWithFormat:
@"http://mlb.mlb.com/gdcross/components/game/mlb/year_2010/month_08/day_17/master_scoreboard.xml"];
NSURL *url=[NSURL URLWithString:urlString];
NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData=[NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
if(!urlData){
NSAlert *alert=[NSAlert alertWithError:error];
[alert runModal];
return nil;
}
return urlData;
}
@end
-(IBAction)getData:(id)sender{
ScoreEngine *holdData=[[ScoreEngine alloc]init];
NSData *myMLB;
myMLB=[holdData loadData]; // urlData passed to myMLB
[myGames release];
myGames=[[gameStatusXML nodesForXPath:@"//alerts" error:&error]retain];
NSLog(@"myGames array size=%d",[myGames count]);
NSLog(@"myGames=%@",myGames); // everything looks happy
NSXMLElement *specificAlert=[myGames objectAtIndex:0]; // just focusing on 1st element of array
NSLog(@"specificAlert to start=%@",specificAlert); // everything happy
NSString *findAlerts;
findAlerts=[specificAlert stringValue]; // attempting to create a string
NSLog(@"findAlerts=%@",findAlerts); // no value… unhappy
}
@end_______________________________________________
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