Comparing 2 xml files in C#???

Author
Discussion

Dupont666

Original Poster:

21,612 posts

193 months

Thursday 22nd May 2008
quotequote all
Im looking to compare 2 xml files and output the changes, without using a seperate program (3rd party) to do so.

xml has a header and then repeating sections (nested nodes), this just needs a direct file compare and then specifiying the nodes that dont match.

Help please.

pdV6

16,442 posts

262 months

Thursday 22nd May 2008
quotequote all
Could do worse than using fc to compare the files. I know its not strictly what you asked for, but you don't need to buy anything!

dilbert

7,741 posts

232 months

Thursday 22nd May 2008
quotequote all
I think DOM is available with a COM interface. You just create an instance of a parser, collect and compare whatever you want in the tree(s), and spit out the results. Available on all platforms that would support C# (except perhaps mobile).

Perhaps you could even do it, byte by byte.

{{{
using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");

// Save the document to a file.
doc.Save("data.xml");
}
}
}}}

Copied form the manual.

Edited by dilbert on Thursday 22 May 17:38

Dupont666

Original Poster:

21,612 posts

193 months

Thursday 22nd May 2008
quotequote all
Cheers will look at both of them, unfortunately all the examples I see are about combining files rather than comparing them.


GHW

1,294 posts

222 months

Thursday 22nd May 2008
quotequote all
http://www.mathertel.de/Diff/

It's the daddy of all text diff algorithms - could be worth a look, even if it's not XML-specific.