我正在练习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]);
}
}
}
答案 0 :(得分:0)
您从解析器获得的错误是NSXMLParserEmptyDocumentError
。看来你没有得到你期望从服务器得到的响应;这不是解析器的问题。
您应该检查连接或响应是否发生错误,结果实际上是XML文档。