Comparing two xml files in Objective-C
compare, file, objective-c
Solution
You could also use:
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr contentsEqualAtPath:PathToAXML andPath:PathToBXML])
NSLog (@"File contents match");
else
NSLog (@"File contents do not match");
Problem
I have two xml files (a.xml and b.xml) in my file system (iPhone). Now I want to know if these files contain exactly the same data. Most of the time, this comparison would be true, because b.xml is the result of a copyItemAtPath: operation. Unless it is overwritten by newer information. What would be the most efficient way to compare these files? - I could read the contents of the files as strings and then compare the strings - I could parse the files and compare some key elements - I guess there is a very blunt way, that doesn't need to interpret the file, but allows me to compare on a lower level. Any suggestion is very welcome. Thanks ahead Sjakelien Update: I ended up doing this: ``` oldData = [NSData dataWithContentsOfFile:PathToAXML]; newData = [NSData dataWithContentsOfFile:PathToBXML]; ``` and then compare it with: ``` [newData isEqualToData:oldData]; ``` The question is still: is that more efficient than: ``` oldData = [NSString dataWithContentsOfFile:PathToAXML]; newData = [NSString dataWithContentsOfFile:PathToBXML]; [newData isEqualToString:oldData]; ```