开发者

iPhone SDK: verify XML before processing it?

开发者 https://www.devze.com 2022-12-19 08:58 出处:网络
Is there a way to verify / validate a remote开发者_高级运维 XML (or download it first and store it locally) before processing it and store the info into CoreData or DB with iPhone SDK 3?In Cocoa you c

Is there a way to verify / validate a remote开发者_高级运维 XML (or download it first and store it locally) before processing it and store the info into CoreData or DB with iPhone SDK 3?


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 a NSXMLDocument

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

and get the nodes with

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

Don't know if all of this works on the iPhone.

0

精彩评论

暂无评论...
验证码 换一张
取 消