iPhone: NSXMLParser problems
iPhone: NSXMLParser problems
- Subject: iPhone: NSXMLParser problems
- From: "Eric E. Dolecki" <email@hidden>
- Date: Tue, 5 Jan 2010 00:09:06 -0500
I am an XML parsing noob, but I do it all the time in AS3, etc. I have the
following methods... I was expecting something to be called in the delegate
methods, but I don't get anything. Shouldn't I be getting something...
although the Yahoo! API is supposed to return XML, it's really a weird
bastardization of XML and HTML:
- (void)parserDidStartDocument:(NSXMLParser *)parser {
NSLog(@"parserDidStartDocument");
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError
*)parseError {
NSLog(@"Parsing Error");
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict {
NSLog(@"didStartElement");
//not sure how to handle namespaces in obj-c
if( [elementName isEqualToString:@"yweather:condition"]){
NSString *thisOwner = [attributeDict objectForKey:@"text"];
NSLog(@"%@", thisOwner);
}
}
// I send this a string, ie. 01701
+(NSString*)getWeatherXmlForZipCode: (NSString*)zipCode {
NSError *error;
NSURLResponse *response;
NSData *dataReply;
NSString *stringReply;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL
URLWithString: [NSString stringWithFormat:@"
http://weather.yahooapis.com/forecastrss?p=%@", zipCode]]];
[request setHTTPMethod: @"GET"];
dataReply = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
stringReply = [[NSString alloc] initWithData:dataReply
encoding:NSUTF8StringEncoding];
NSString *header = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
NSString *xml = [NSString stringWithFormat:@"%@\n%@", header, stringReply];
NSData *data = [xml dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];//should allow the methods above to be called when
I parse?
[parser setShouldResolveExternalEntities:YES];
[parser setShouldProcessNamespaces:YES];
[parser parse];
//NSLog(stringReply);
return stringReply;
}
_______________________________________________
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