Comparing Two Open XML Packages with Open XML Diff

Yesterday I received an email from another employee here at Microsoft to check out this tool called Open XML Diff that he was working on. His name is Pranav Wagh and he just released another drop of the tool which you can read about oh his blog.

You can use Open XML Diff when writing code to generate an Open XML document when you’re not quite sure what XML it is that you need to write. Say you know how you want the document to render in Word, but are unsure about which element or attribute to tweak.  You can save a copy of a doc, modify it, save it again, and compare the two which helps you figure out what XML you need.

I downloaded the source but had a couple trust issues on my Vista box because the projects are looking for the xmldiffpatch.dll, which the instructions said to install first from here, but that setup places the assembly off of C:\Program Files\ and it’s a NO NO in Vista to reference assemblies there. Then I noticed that Pranav was supplying the xmldiffpatch.dll in the OpenXMLDiff\bin\Release folder already. So I created a single solution for the three projects and set a project reference from the OpenXMLComparer Winforms client to the OpenXMLDiff library and another project reference from the OpenXMLDiff library to the ViewRenderer project. Then the only binary reference you need to set up is to the xmldiffpatch.dll. Finally I set the OpenXMLComparer as the startup project and rebuilt the whole solution without problems.

So to test the tool I took the MyDocument.docx Word document from my last post that just contains the text "This is my document." and saved a copy called MyDocument1.docx and made a simple change; I made the entire sentence bold. Then I compared the two documents. The report found three xml files in the package that changed. The important one being the MainDocument part, document.xml. Here’s a snapshot of part of the report where you can see the differences:

Pretty slick! It really helps me understand what changes are applied to the Open XML package based on changes I make through Office. Much more intuitive than reading Office specs ;-)

Make sure to provide feedback on the Open XML Diff site.