Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helo,
I wanna compare 2 xml files with eachother. both on xml file is standard on my pc. one is College.xml,and another is books.xml.how is it posible . actually i m not using any internet tools just like (altova,beyond). i want to create my tools

plz send me the code of comparing two file of xml and also create the tools

eg:-

XML
<body>
    <form id="form1" runat="server">
    <div>
    <table width="1200px" cellpadding="2" cellspacing="2" border="2">
    <tr>
    <td align="left" valign="top">
    <div>
    <p></p>
    </div>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <asp:FileUpload ID="FileUpload1" runat="server" />

            </td>
    <td align="right" valign="top">
    <asp:TextBox ID="txtXMLFileDestination" runat="server"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <asp:FileUpload ID="FileUpload2" runat="server" />
      </td>
    </tr>
      <tr>
    <td align="center" valign="top" colspan="2">

      <asp:Button ID="imgbtnCompare" runat="server" Text="Compare" Font-Bold="true" Font-Size="Large" />
        </td>
    </tr>
      <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="right" valign="top">&nbsp;</td>
    </tr>
    </table>
    </div>
    </form>
</body>
Posted
Comments
Richard MacCutchan 25-Mar-14 7:41am    
plz send me the code of comparing two file of xml and also create the tools

Sorry, but this site does not provide code to order; you are expected to do your own work. When you have specific questions then post them here and people will try to help you.

1 solution

Hi ashishmagneti
XML comparison is no easy task, and especially when it comes to writing your own diff tool. The Microsoft already has a tool which does exactly comparing: Diff two XML files and give me back the differences.

You will first need to download the assembly here[^] to use the tool.
I'll go ahead and jump into some code which does a very basic comparison of two different files of xml, and returns the difference to an XMLWriter:
C#
// This is the namespace:
using Microsoft.XmlDiffPatch;

The code is then very simple:
C#
System.Xml.XmlWriter xml_writer = System.Xml.XmlWriter.Create("C:\diff.xml");

// There are a number of available options in the XmlDiffOptions enum
XmlDiff diff = 
new XmlDiff(XmlDiffOptions.IgnoreChildOrder | 
            XmlDiffOptions.IgnoreComments   | 
            XmlDiffOptions.IgnoreWhitespace);
diff.Compare("C:\file1.xml", 
             "C:\file2.xml", 
             true, 
             xml_writer);


Regards,
Alex
 
Share this answer
 
Comments
ashishmagneti 26-Mar-14 0:44am    
sorry but i did not get the assembly that you provided so plz send it.
Volynsky Alex 26-Mar-14 5:05am    
http://msdn.microsoft.com/en-us/library/aa302294.aspx
http://msdn.microsoft.com/en-us/library/aa302295.aspx

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