DCP and the Document Comparator
For this sample we will use XML Compare's Document Comparator component. We show how extensions to its built-in processing pipeline can be conveniently accessed using the included Document Comparator Pipeline (DCP) definition file 'diffreport.dcp'.
More information on the Document Comparator and DCP can be found here:
The Folding DiffReport
XML Compare includes built-in XSLT stylesheets for rendering XML comparison results using HTML to highlight differences at the syntax-level; this sample focuses on the 'folding' view, but there is also a 'side-by-side' view. The 'side-by-side' view is similar to the folding DiffReport but shows two synchronised-scrolling folding XML views
A folding DiffReport shows formatted XML syntax with folding points highlighted with an arrow icon. Clicking on the arrow either folds or unfolds the adjacent XML, depending on its current view state. When the comparison result is first rendered, nodes with fold-points that have changes are shown expanded and all other fold-points are collapsed. Nodes that have changes have start and end tags coloured in blue, unchanged nodes are shown in grey.
A screenshot of the DiffReport as rendered in a browser:
A simple toolbar along with a 'breadcrumb' view of the currently selected change is shown above the folding view in the DiffReport, there is also a 'Differences List' shown as a vertical panel alongside.
Using DCP to add an output filter
To render a folding DiffReport, it is necessary to add the included XSLT resource
xsl/dx2-deltaxml-folding-html.xsl as the final output filter (this XSLT is also available externally in the samples/xsl-filters directory). The following snippet from the DCP file shows how this is done:
The code above shows one of the available parameters for the DiffReport XSLT using a parameterRef attribute to associate it with a DCP parameter. (Note: for a 'side-by-side' change the resource name to 'dx2-deltaxml-sbs-folding-html.xsl'). A full description of all the DCP parameters is shown using the command-line. Replace x.y.z with the major.minor.patch version number of your release e.g. command-10.0.0.jar
'dcp-folding' is the configuration id included in the DCP file. The output from running the above command summarises the purpose of this DCP and briefly describes each of the defined DCP parameters, as seen below.
Running the sample
The sample code can be downloaded from Bitbucket https://bitbucket.org/deltaxml/folding-diffreport.
Details of how to run the sample are given in the file README.md.
What the Sample Does
The sample code performs two comparisons using the Document Comparator. Each uses the same DCP file to configure the comparator, but with the convert-to-html parameter set true in the first comparison and false in the second.
The output files from the two comparisons are
result2.xml. The latter file is the 'delta' XML output, which is initially harder to understand than the html-rendered DiffReport, but may be useful for reference.
Notes on DCPConfiguration Java API
The DCPConfiguration class in the samples is used to manage DCP configurations using the API. This class has 'generate' and 'setParams' methods that are used to create or modify a DocumentComparator configured using the DCP file. Any parameter overrides are supplied within Map arguments for these methods. Full source code is included in the DCPConfigurationSample.java source file. A snippet is shown below.