IPhone SDK: check XML before processing it?

Is there a way to check / verify the remote XML (or download it first and save it locally) before processing it and save the information in CoreData or DB from the iPhone SDK 3?

+3
source share
1 answer

In Cocoa, you can just download it

NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url 
                                            cachePolicy:NSURLRequestReturnCacheDataElseLoad 
                                        timeoutInterval:30];

NSData *urlData;
NSURLResponse *response;
NSError *error = nil;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest 
                                returningResponse:&response 
                                            error:&error];

and load it into NSXMLDocument

NSXMLDocument *doc = [[NSXMLDocument alloc] 
                              initWithData:urlData options:0 error:&error];

and get nodes with

NSArray* tempArray = [doc nodesForXPath:@"something/anotherthing"       error:&error];

I don’t know if it all works on the iPhone.

0
source

Source: https://habr.com/ru/post/1731959/


All Articles