Comparing two xml files in Objective-C

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. In most cases, this comparison would be true, since b.xml is the result of the copyItemAtPath: operation. If it will not be overwritten with new information. What would be the most efficient way to compare these files?

  • I could read the contents of files as strings and then compare strings
  • I can analyze files and compare some key elements
  • I think there is a very dumb way that does not need to interpret the file, but allows me to compare at a lower level.

Any suggestion is very welcome.

thanks in advance

Sjakelien

Update:

I ended up with this:

oldData = [NSData dataWithContentsOfFile:PathToAXML];
newData = [NSData dataWithContentsOfFile:PathToBXML];

and then compare it with:

[newData isEqualToData:oldData];

: , :

oldData = [NSString dataWithContentsOfFile:PathToAXML];
newData = [NSString dataWithContentsOfFile:PathToBXML];

[newData isEqualToString:oldData];
+5
4

:

NSFileManager *filemgr = [NSFileManager defaultManager];

if ([filemgr contentsEqualAtPath:PathToAXML andPath:PathToBXML])
  NSLog (@"File contents match");
else
  NSLog (@"File contents do not match");
+5

- - , , , .

. fileAttributesAtPath:traverseLink: NSFileManager.

+3

Is there a reason why you don't want to do something like an MD5 hash of two files and compare the results - here is an example of some code that seems pretty common

Gravatar for Iphone? How to create an MD5 hex hash?

+2
source
BOOL filesAreEqual = [[NSData dataWithContentsOfMappedFile:file1] isEqual:[NSData dataWithContentsOfMappedFile:file2]];
+1
source

All Articles