앱 하나 개발해보겠다고.. 웹데이터좀 얻으려고했더니.. 좋아하지도 않은 웹프로그래밍을 계속보게되네...
이건 뭐.. -_-;; 아우.. 힘들어;;
덕분에 XML이고 RSS고.. 듣기만 했던걸 다 이해하는중...
이 엄청난분의 강의에 힘입어 열강 하는중... !
왜!!! 정작 내가 필요한 openAPI소스만 파싱이 되질않는다... T_T
언제까지 삽질을 해야 하는건가...
#import "FirstParserViewController.h"
@implementation FirstParserViewController
@synthesize parser;
@synthesize stnid;
@synthesize desc;
@synthesize ta;
@synthesize name;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// XML 파싱
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[superviewDidLoad];
//NSURL *XMLURL = [NSURL URLWithString:@"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml"];
NSURL *XMLURL = [NSURLURLWithString:@"http://www.kma.go.kr/XML/weather/sfc_web_map.xml"];
parser = [[NSXMLParseralloc] initWithContentsOfURL:XMLURL];
[parsersetDelegate:self];
[parserparse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
//NSLog(@"didStartElement..!");
if([elementName isEqualToString:@"local"])
{
stnid = [attributeDict objectForKey:@"stn_id"];
desc = [attributeDict objectForKey:@"desc"];
ta = [attributeDict objectForKey:@"ta"];
NSLog(@"%@",stnid);
NSLog(@"%@",desc);
NSLog(@"%@",ta);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"didEndElement..!");
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
NSLog(@"foundCDATA");
NSMutableData *decode = [NSMutableDatadataWithData:CDATABlock];
constunsignedchar tempcstring = 0;
[decode appendBytes:&tempcstring length:1];
NSString *string = [NSStringstringWithUTF8String:(constchar*)[decode bytes]];
NSLog(@"%@",string);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if([string isEqualToString:@""])
{
;
}
else
{
name=string;
NSLog(@"%@",string);
}
//NSLog(@"foundString!!");
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSLog(@"Error");
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[superdidReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[superdealloc];
[parserrelease];
[stnidrelease];
[descrelease];
[tarelease];
[namerelease];
}
@end
설..마.. .이거 IE로 보면 검은 글씨에 태그가 다 깨진건 아닌지...-_-;; 확인해봐야겠군..