views:

510

answers:

1

Hi friends,

I have a folder structure in my server and I need to navigate through that folder at device side. I receive the folder structure in XML format. My query is :- 1) Can I create the same folder structure in documents folder of my iPhone app.

2) What would be the best approach whether to create folders at device documents folder or just read the XML and show the folders as we parse it(I mean no folder creation).

Waiting for your reply

+1  A: 

I'm not 100% sure of your question, but I think this is what you're after...

First, you have to parse the XML from your server. You can do this with the built in NSXMLParser or with one of the various XML-parsers and document handlers out there. A few alternatives:

Then, you can create directories on your iPhone applications own document folder using the following code. I will assume you have a NSArray named directories containing some directory names as NSStrings.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];

for (NSString *directory in directories) {
    NSString *directoryPath = [storagePath stringByAppendingPathComponent:directory];
    [[NSFileManager defaultManager] createDirectoryAtPath: directoryPath attributes:nil];
}

This code is of course very simple and does not include support for adding a entire folder structure (just the first level). But you get the idea.

alleus
thanks for the help 1) can you give a code snippet for folder structure creation.2) I want to save only the name of the files(if a file is there inside the folders) if it is there in XML and for folders I will create the folder at my app documents.
Ekra
I'm afraid that's something I don't really have time for mate. You should look into parsing XML and just use the code i wrote to create the folder structure recursively.I'm not sure why you would create a bunch of folders and just add empty files in them though. What's the reason for creating the folders if your're not going to store anything in them?
alleus