我有这样的功能,将通过一个请求操作得到的xml:返回字符串
-(id)xmlRequest:(NSString *)xmlurl
{
AFKissXMLRequestOperation *operation = [AFKissXMLRequestOperation XMLDocumentRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:xmlurl]] success:^(NSURLRequest *request, NSHTTPURLResponse *response, DDXMLDocument *XMLDocument) {
NSLog(@"XMLDocument: %@", XMLDocument);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, DDXMLDocument *XMLDocument) {
NSLog(@"Failure!");
}];
[operation start];
return operation;
}
这是我的代码调用该函数:
Request *http=[[Request alloc] init];
NSString *data=[http xmlRequest:@"http://legalindexes.indoff.com/sitemap.xml"];
NSError *error;
DDXMLDocument *ddDoc=[[DDXMLDocument alloc] initWithXMLString:data options:0 error:&error];
NSArray *xmlItems=[ddDoc nodesForXPath:@"//url" error:&error];
NSMutableArray *returnArray = [[NSMutableArray alloc] initWithCapacity:[xmlItems count]];
for(DDXMLElement* itemElement in xmlItems){
DDXMLElement *element = [[itemElement nodesForXPath:@"loc" error:&error] objectAtIndex:0];
NSLog(@"valueasstring %@", element);
[returnArray addObject:element];
}
我需要的xmlRequest到返回一个字符串,所以我可以得到的XML,但[操作开始]创建正确的输出,但我不能把它放在一个字符串。我怎样才能将输出导入字符串?
你试过'返回[操作开始]'? – 2012-07-10 19:22:38
(我不知道AFKissXMLRequestOperation是什么,或者它的'operation'方法。) – 2012-07-10 19:23:51
好吧,它是NSOperation的子类。所以你开始一个NSOperation,并且没有办法同步获得异步操作的结果。您需要监视完成的操作,然后在此例程之外获取结果。 – 2012-07-10 19:27:14