Monday, July 15, 2013

how to compare two xml files in using c#

Title:How to compare XML files in using C#


Now i would like to give an examples on Comparing of XML documents using C# provide an algorithm which is "hash algorithm",can be used for encryption.So based on those methods i will do the comparison of files In the below method i have use two parameters which indicates the path of XML files

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Security.Cryptography;

private void CompareXMLDocumnet(string ActualDocumnet,string GenratedDocument)
if (File.Exists(ActualDocumnet) && File.Exists(GenratedDocument))
HashAlgorithm HA = HashAlgorithm.Create();
FileStream XmlFstream1 = new FileStream(ActualDocumnet, FileMode.Open);
FileStream XmlFstream2 = new FileStream(GenratedDocument, FileMode.Open);
byte[] Actual_Xmlhash1;
byte[] Genrated_Xmlhash2;
Actual_Xmlhash1= HA.ComputeHash(XmlFstream1);
Genrated_Xmlhash2= HA.ComputeHash(XmlFstream2);
if (Convert.ToBase64String(Actual_Xmlhash1) == Convert.ToBase64String(Genrated_Xmlhash2))
Response.Write(" similar="">
throw new Exception("Files are different");
Post a Comment