Search Wiki:
This utility was written with the following things in mind:
  1. You should be able to differenciate between two OpenXML files easily.
  2. You should be able to see the differences easily.
  3. You should be able to control the output.
  4. You should be able to use it from your code.

It was inspired (and is a vNxt) of the utility that Eric presented on his blog A utility to find differences between two files. I'll be posting further details about this utility on my blog

Briefly, it takes the input OpenXML files, uses OpenXML SDK to get to the parts, finds the difference between the parts using xmldiff and then uses the resultant diffgram to render the part xml and present it in an HTML format.

Prerequisite: Please download and install XML Diff and Patch before using this utility, as it's a dependency.
Usage:Install XML Diff and Patch, Unzip binaries to a folder, and you should be good to go :). I hope you have all the dependencies, but still, I'll be uploading a setup very soon



OpenXMLDiff.dll


This is the meat of the utility; here is the description of its public interface.

Public Properties
It has several properties, some of them are read write and some of them are read only. Generally, I've exposed read only properties as an alternate way for the users to extract the information in the program. The read/write properties are the the ones which are used for comparison parameters (giving the path, algorithm to be used et cetera)
  • Files - This is used to set different paths. You can set 4 paths - SourceFilePath and TargetFilePath (these are the files to be compared, so obviously required), OutputPath(is the path where you want to write your output. If you don't provide a path, I'll use user's temp path) and ResourcePath (If you've customized JS and/or CSS files provided, you might want to keep the customized files in a folder, and provide this path as a resource path, so that the application can use these files for rendering HTML)
  • Format - Report can be generated in two formats, HTML and Text.
  • Algorithm - You can choose from two algorithms to generate the output; fast (walk-tree) or precise (tree-distance)
  • Options - You can use following options to control the comparison. This property has two overloads, either you can set individual properties to "true of false" or you can "Or" a few properties and set all of them togather.
    • IgnoreChildOrder
    • IgnoreComments
    • IgnoreProcessingInstructions
    • IgnoreWhiteSpaces
    • IgnoreNameSpaces
    • IgnorePrefixes
    • IgnoreXmlDeclaration
    • IgnoreDTD
  • RemoveFiles - If you set this property to true, it will remove all the output files after the report is generated(Use this only when you don't want to read files from the filesytem and want to read all the information from the properties)
  • Output(readonly) - This property can be accessed after the report is generated, to get the complete output (HTML/Text whichever you choose) as a string.
  • OutputFileName(readonly) - This property can be used to get the name of the file after the output is generated.
  • SourceParts(readonly) - This is a dictionary of strings of all the parts from the source which were found to be different.
  • TargetParts(readonly) - This is a dictionary of strings of all the parts from the target which were found to be different.
  • Diffs(readonly) - This is a dictionary of strings of diffgrams which tell the exact differences between the parts.
  • Css(readonly) - This is the CSS string used to render the HTML output.
  • JS(readonly) - This is the JS string used to add extra functionality to the output.

Public Method(s)
It has only one method - Generate; with 4 overloads, It can be used in the following ways
  • Generate() - Without using any parameters, It will be assumed that you've already set the required parameters using class properties.
  • Generate(string) - Only one parameter, it will be assumed that you've passed output path in the method and you've set rest of the required parameters using class properties
  • Generate(string,string) - Two parameters, it will be assumed that these are the source and target file paths, if you've set other class properties, they'll be used.
  • Generate(string,string,string) - Three parameters, it will be assumed that these are the source, target and output paths.

Event(s)
It has only one event, which is fired when the report generation is complete. It passes output as String,sourceparts as Dictionary(Of String, String), targetparts as Dictionary(Of String, String), diffparts as Dictionary(Of String, String), jsString as String and cssString as String. You can either use this event to get these objects or you can use the properties for getting the same information.

Enum(s)
It has a few public enums which are available to ease your dev efforts while using properties and methods.

OpenXMLComparer.exe


This is a sample windows application, which demonstrates how to use the class library explained above. As it already does the required job, you can use it as it is if you don't want to write your own tool.

How can you use it?

In multiple ways;
  • You can roll your own tool around this class library and get the results.
  • You can use the sample application provided to find the differences between two files.

How can you customize the output?

In multiple ways;
  • You can change the code directly; it's included!
  • You have an option of selecting HTML/Text output
  • You can customize the CSS, which is used to render the output.
  • You can customize the JS, which is used to add actions to the output. While customizing the JS, If you need to call some functionality which should be executed after the output is loaded, you can write code in JS Initialize method.
  • You can control JS/CSS in a broder level by using a "ResourcePath" and keeping your customized JS/CSS there.
  • You can also control the output granularly by avoiding the "ResourcePath" and modifying JS/CSS in the output folder.

How can you help?

In multiple ways;
  • Give us feedbacks; let us know what did you like in the utility and what you didn't.
  • Submit bug reports.
  • Modify the CSS/JSS, and share it with us - so that we can improve output presentation and others can also benefit from your JS/CSS skills.
  • Write tools around it, and share it with us - so that others can use those tools to increase their productivity.

Last edited Jul 11 2008 at 9:18 PM  by pranavwagh, version 9
Updating...
Page view tracker