0

i do this for writeToFile my XML file :

NSURL *url = [NSURL URLWithString:loadFlux];
        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

        // Load XML data from web
        NSData *data = [NSData dataWithContentsOfURL:url];
        // construct path within our documents directory
        NSString *applicationDocumentsDir = 
        [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"flux.xml"];
        // write to file atomically (using temp file)
        [data writeToFile:storePath atomically:TRUE];
        [prefs setValue:storePath forKey:@"CheminVersXML"];

        //Initialize the delegate.
        XMLToObjectParser *parser = [[XMLToObjectParser alloc] initXMLParser];

        //Set delegate
        [xmlParser setDelegate:parser];

        //Start parsing the XML file.
        BOOL success = [xmlParser parse];

        if(success)
            NSLog(@"No Errors");
        else
            NSLog(@"Error Error Error!!!");

and to load i do this :

// Load XML data from file
        NSData *data = [NSData dataWithContentsOfFile:storePath];
        // write to file atomically (using temp file)

        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];

        //Initialize the delegate.
        XMLToObjectParser *parser = [[XMLToObjectParser alloc] initXMLParser];

        //Set delegate
        [xmlParser setDelegate:parser];

        //Start parsing the XML file.
        BOOL success = [xmlParser parse];

        if(success)
            NSLog(@"No Errors");
        else
            NSLog(@"Error Error Error!!!");

but i still have a probleme : my picture dont load (url) and my dynamic string too (guid).

My XML file is here

Thank you for your help

EDIT : how can i do offline, the first launching is online and i need to save all data for a probably offline launch...

JioGray
  • 19
  • 9

1 Answers1

0

You need to implement the NSXMLParserDelegate methods, at last you need to write

– parser:didStartElement:namespaceURI:qualifiedName:attributes:
– parser:didEndElement:namespaceURI:qualifiedName:
– parser:parseErrorOccurred:
– parser:foundCharacters:

Please refer to documentation here and for an example here or here to solve your ploblem, so yo will need to use NSURLConnection to retreive the image and url content. Cheers!

Community
  • 1
  • 1
D33pN16h7
  • 2,030
  • 16
  • 20
  • ok thanks but my problem is when i'm offline (online all works perfectly) i need to save the image and the dynamic string, but nothing happend, zones still blank... sorry if i forgot to mention that :s – JioGray Nov 02 '11 at 12:06