How we can compare to XML files.
I need to compare the two XML files for that i need some generic code.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bechir BejaouiPosted Dec 20, 2008, 8:02 AM
public class XmlComparer : IComparer
{
public string FirstFilePath { get; set; }
public string SecondFilePath { get; set; }
public int Result = 0;
#region IComparer
public int Compare(System.Xml.XmlDocument x, System.Xml.XmlDocument y)
{
x.Load(FirstFilePath);
y.Load(SecondFilePath);
/* Then you do compare the two files, I don't know the
* comparaison your criteria exactly is it the lenght or other criteria*/
if(/*Condition1*/)
{
Result = 0;
return Result;
}
else if(/*Condition2*/)
{
Result = 1;
return Result;
}
else
{
Result = - 1;
return Result;
}
//Then you can make the decision based on the
//Result value, this is the magic effect using
//The generic with the comparer interface
}
#endregion
}
Mahesh ChandPosted Dec 17, 2008, 10:42 PM
One way you could do is, load two XML files into two DataSet objects using DataSet.LoadXml method. After that, you can compare two DataSets. Read here:
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic16270.aspx