#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
'프로그래밍 > Objective C' 카테고리의 다른 글
APPLE :: SelectString (문장 잘라내기) (0) | 2010.11.10 |
---|---|
APPLE :: Loading Screen(시작 로딩 화면) (0) | 2010.11.10 |
APPLE :: IPhone On OpenCV (0) | 2010.11.03 |
APPLE :: Object-C Array (0) | 2010.11.03 |
APPLE :: Objective-C의 기본문법 (0) | 2010.11.01 |