WEB开发网
开发学院手机开发iPhone 开发 iOS开发笔记:网络编程总结 阅读

iOS开发笔记:网络编程总结

 2010-10-13 02:04:00 来源:本站整理   
核心提示:qualifiedName:(NSString *)qNameattributes:(NSDictionary *)attributeDict;- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementNamenamespaceURI:(

qualifiedName:(NSString *)qName

attributes:(NSDictionary *)attributeDict;

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName

namespaceURI:(NSString *)namespaceURI

qualifiedName:(NSString *)qName;

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError;

static NSString *feedURLString = @"http://www.yifeiyang.net/test/test.xml";

3. 应用举例

- (void)parseXMLFileAtURL:(NSURL *)URL parseError:(NSError **)error

{

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];

[parser setDelegate:self];

[parser setShouldProcessNamespaces:NO];

[parser setShouldReportNamespacePrefixes:NO];

[parser setShouldResolveExternalEntities:NO];

[parser parse];

NSError *parseError = [parser parserError];

if (parseError && error) {

*error = parseError;

}

[parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI

qualifiedName:(NSString*)qName attributes:(NSDictionary *)attributeDict{

// 元素开始句柄

if (qName) {

elementName = qName;

}

if ([elementName isEqualToString:@"user"]) {

// 输出属性值

NSLog(@"Name is %@ , Age is %@", [attributeDict objectForKey:@"name"], [attributeDict objectForKey:@"age"]);

}

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI

qualifiedName:(NSString *)qName

{

// 元素终了句柄

if (qName) {

elementName = qName;

}

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

{

// 取得元素的text

}

NSError *parseError = nil;

[self parseXMLFileAtURL:[NSURL URLWithString:feedURLString] parseError:&parseError];

上一页  1 2 3 4 5 

Tags:iOS 开发 笔记

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接