자료 저장소

# XML 파싱

앱 하나 개발해보겠다고.. 웹데이터좀 얻으려고했더니.. 좋아하지도 않은 웹프로그래밍을 계속보게되네...
이건 뭐.. -_-;; 아우.. 힘들어;;

덕분에 XML이고 RSS고.. 듣기만 했던걸 다 이해하는중...

http://yooninsung.blog.me/30089076019

이 엄청난분의 강의에 힘입어 열강 하는중... !


기상청 XML 데이터 파싱


트위터나 티스토리 RSS랑 뭐 관련 자료들은 잘 파싱이 되는데... 

왜!!! 정작 내가 필요한 openAPI소스만 파싱이 되질않는다... T_T

언제까지 삽질을 해야 하는건가...



<.m파일,  재활용을 위해 ㅋ>

#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로 보면 검은 글씨에 태그가 다 깨진건 아닌지...-_-;; 확인해봐야겠군.. 
댓글 로드 중…

최근에 게시된 글