Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a console app that allows for someone to output and XML file. What I need is to be able to check every time it is run whether or not the XML file has changed and if so to increment it? Any ideas?
C#
XmlDocument doc = new XmlDocument();
if (doc.LastChild.Value == lsat saved doc)
{
   // My code here.
}
Posted
Updated 16-Aug-11 3:38am
v2

You could try creating an MD5 hash of the xml file and check if the hashes are equal. You know the rest.
 
Share this answer
 
Comments
TomGorton 16-Aug-11 10:03am    
how would you do that? load the file and take the text from it or do you just put the whole file into it?
There are times when a MD5 hash could result in an identical result. I would perform several checks that took gradually more time:

0) See if the file sizes are the same

1) If they are the same size, load the files as text strings, eliminate the white space, and do a simple equality comparison.
 
Share this answer
 
it was alright in the end i just used
C#
if (doc.InnerXml.Length != doc2.InnerXml.Length)
           {
               UpdateLatestVersion(newVersion);
           }
 
Share this answer
 
Comments
Philippe Mori 16-Aug-11 18:23pm    
If you change one string to another one of the same length, it will fails to detect a change.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900