0

我有这个函数可以通过请求操作获取 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,但是 [操作开始] 创建正确的输出,但我不能将它放入字符串中。如何将输出定向到字符串?

4

1 回答 1

1
于 2012-07-11T02:44:01.317 回答