我正在练习 RESTKit,所以我正在构建一个 Dribbble 客户端来掌握 REST,我成功获得了 XML 响应,但是当我使用 NSXMLParser 解析它时,它记录开始,然后立即停止,我该如何修复它,或者只是让 XML 更容易区分哪个项目是哪个项目,然后将其放入我的表中?
继承人的代码:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
NSLog(@"I just found a start tag for %@",elementName);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"the parser just found this text in a tag:%@",string);
}
-(void)parserDidStartDocument:(NSXMLParser *)parser {
NSLog(@"starting");
}
-(void)parserDidEndDocument:(NSXMLParser *)parser {
NSLog(@"end");
}
-(IBAction)test {
[[RKClient sharedClient] get:@"/shots/popular" delegate:self];
}
-(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
if ([request isGET]) {
NSLog(@"Retrieved XML: %@", [response bodyAsString]);
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[response body]];
[xmlParser setDelegate:self];
[xmlParser parse];
}
else if ([request isPOST]) {
if ([response isJSON]) {
NSLog(@"Got a JSON response back from our POST!");
}
}
else if ([request isDELETE]) {
if ([response isNotFound]) {
NSLog(@"The resource path '%@' was not found.", [request resourcePath]);
}
}
}