How we can compare to XML files.
I need to compare the two XML files for that i need some generic code.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mahesh ChandRank #1 · 393.3K reputationPosted Dec 17, 2008, 5:42 PM EST
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
Bechir BejaouiRank #144 · 15.9K reputationPosted Dec 20, 2008, 3:02 AM EST
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
}