Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: URL caching with XMLDoc from url



Eric Blanpied skrev:
I'm using NSXMLDocument's initWithContentsOfURL: method, and I think I'm running into some issues with NSURL caching the data at times. I see that there are lots of options with NSURLRequest and it's brethren, but it's not clear to me how to merge this with the NSURL required by NSXMLDocument's initWithContentsOfURL:

Any pointers on this would  be great.

The NSURL instance that NSXMLDocument's initWithContentsOfURL:options:error: wants is simply just an URL, like http://foo.com/xml.php or file://Users/peylow/test.xml.

The NSURLRequest is a bit more complex, it can also post form data and such. I can not see any way to swap the two unless you also use the NSURLRequest object with a NSURLConnection's sendSynchronousRequest:returningResponse:error: method to get a NSData object. And then use that to init the NSXMLDocument using the initWithData:options:error: method instead.

Something like:
NSURL *url = [NSURL URLWithString:someURLString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data options:NSXMLNodeOptionsNone error:nil];


But my guess is that this is pretty much what initWithContentsOfURL:options:error: does internally anyway.


// Fredrik Olsson _______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >URL caching with XMLDoc from url (From: Eric Blanpied <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.