0

I am having a pretty big xml file (17 MB) on a webserver, which is constantly updated (once or twice a month). I take the XML and parse it to Core data, when the user triggers an update. Now I want to check during my Apps wake/start up if the locally parsed database is up to date or if there is a newer xml on the server.

The xml is created by a non-IT-company via MS Office, so I can't really expect them to do many changes to the xml. right now i only have the

<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="someXML.xsd" generated="2012-06-28T12:53:12">

generated Attribute of dataroot.

Any tips on how to get the date the file was created in a fast and neat way?

Amandir
  • 679
  • 1
  • 7
  • 20

3 Answers3

1

I have am giving you the important code. I am taking a string variable in .h file and initializing the string in parse didstartelement method of parsing. Check the below code.

 @interface TestViewController: UIViewController <NSXMLParserDelegate>  {
        NSString *generatedDate;
    }
    @end

#import "TestViewController.h"

@implementation TestViewController

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    if ( [elementName isEqualToString:@"dataroot"] ) {
        generatedDate = [[NSString alloc]initWithFormat:@"%@",[[attributeDict objectForKey:@"generated"] retain]];
        }
   }
@end
Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107
  • Hmm, I was hoping there would be a way to read the date from some file description or header file. But this is fast enough when I abort the parser after the dataroot-tag was found. Thank you :) – Amandir Jul 02 '12 at 10:44
0

Can you not just store and check the created or modified date on the server and compare it to a value you have stored? That way if it is the same you don't even need to bother to read the XML. You could get a false positive (date changed but data hasn't), but you wouldn't get a false negative (data changed but date hasn't), so it would cut down a lot of processing.

Once you have decided it has changed you can either pass the XML to check for the date, of if it is in a specific place of the file (ie, the beginning), just read that much of the file and search for the string

Woody
  • 5,052
  • 2
  • 22
  • 28
0

you can get your generated time using NSXMPParser. use following

NSXMLParser *parser  = [[NSXMLParser alloc] initWithData:yourXMLData];

[parser setDelegate:self];

[parser parse];

This will call your delegate methods. You need to handle following delegate method to get your date

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
     NSString *generatedDate = [attributeDict objectForKey:@"generated"];
}

Hope this helps

Kapil Choubisa
  • 5,152
  • 9
  • 65
  • 100