從請求的原始數據總是在操作等級的responseData
屬性可用。這裏是你如何與NSLog
表現出來:
__block AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://legalindexes.indoff.com/sitemap.xml"]] success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
NSLog(@"Parser: %@", XMLParser);
NSLog(@"Raw XML Data: %@", [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser) {
NSLog(@"Failure!");
}];
[operation start];
這就是說,標準AFXMLRequestOperation
類使用NSXMLParser
這是痛苦的使用。如果您的有效載荷不太大,性能是不是一個問題,我建議你使用Mattt新AFKissXMLRequestOperation類會做解析,爲您和暴露一個友好NSXMLDocument兼容的對象:
__block AFKissXMLRequestOperation *operation = [AFKissXMLRequestOperation XMLDocumentRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://legalindexes.indoff.com/sitemap.xml"]] success:^(NSURLRequest *request, NSHTTPURLResponse *response, DDXMLDocument *XMLDocument) {
NSLog(@"XMLDocument: %@", XMLDocument);
NSLog(@"Raw XML Data: %@", [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, DDXMLDocument *XMLDocument) {
NSLog(@"Failure!");
}];
[operation start];
如果您想接收一個完全實例化的xml文檔,請查看我創建的這個請求操作子類https://github.com/shawnwall/AFGXMLRequestOperation – shawnwall