views:

77

answers:

2

hi guys, im currently parsing an xml file that is hosted on another PC via hosting a Apache http server which works fine. Now is it possible to code it in such a way that the iPhone deletes the xml file on that pc?

im currently using a NSMutableURLRequest and setting it to an NSData.

NSError * error; 
NSURLResponse * response;

NSMutableURLRequest *request =
    [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://ipaddress/UserBedData.xml"]
                            cachePolicy:NSURLRequestReloadIgnoringCacheData
                        timeoutInterval:5.0];
[request setHTTPMethod:@"GET"];         
NSData * responseData = [NSURLConnection sendSynchronousRequest:request
                                              returningResponse:&response
                                                          error:&error];
xmlParser = [[NSXMLParser alloc] initWithData:responseData];
+1  A: 

Only if the server lets it. If the web server has WebDAV setup properly, the verb DELETE, with the URL of the file should do it (assuming you supply appropriate credentials, since it's a bad idea to let just anyone delete content).

The deletion is almost identical to the fetch. Simply replace "GET" with "DELETE" and ignore the returned content. There is, however, the question of authentication, which usually doesn't matter when reading a web site, but matters a whole lot when you want to delete some content on the web site. I can't help you on that front, I'm afraid. Also consider @joost's answer, which is probably safer than allowing clients to delete stuff on the server.

Marcelo Cantos
Please don't post code into comments; it's virtually unreadable. Add it to your question.
Marcelo Cantos
Sorry, my bad. so how should i code it?
Kenneth
It's still quite unreadable.
Marcelo Cantos
+1  A: 

How much control do you have over this other server? I assume you have full access.

Consider simply cleaning the XML up periodically. Run a cron job and delete files every hour after you know they aren't needed any more. Maybe create a list on the backend that logs when data has been accessed, so that it can be safely expired.

Without further details on what you're doing, the approach is difficult to narrow down. Why can't you parse the XML on the iPhone e.g.? Can the XML feeds be generated dynamically, so there's no file to clean up? Where is the XML data coming from? This isn't necessarily a situation where posting your code is going to help. You should elaborate on how all the piece fit together (the iPhone app, the remote server, the data) and what you're trying to accomplish.

Is it even a collection of XML files? Or is it always the same one? If it's just one file, why do you need to delete it? Simply overwrite the old one when it gets regenerated (and datestamp it somewhere, so the client who downloads it knows when it's really out of date).

Joost Schuur