W3C DOM object trees can be used to represent an XML document's structure. It may be convenient to:
- pass DOM representations of an XML document as inputs to XML Compare's comparison pipeline, and
- get a DOM document as the result of a comparison.
This sample illustrates how DOM documents can be both passed as input and produced as output from a comparison pipeline.
2. Outline of the Approach
Essentially the approach is to:
- Prepare a Saxon processor
- Prepare a comparator pipeline (which uses the Saxon processor)
- Convert the input DOM documents into Saxon XdmNode trees (using the Saxon processor)
- Perform the comparison;
- Convert the result into a DOM document.
2.1. Preparing a Saxon processor
We construct a new Saxon processor as follows:
2.2. Preparing an XML Compare comparator
We create a pipelined comparator that uses the existing Saxon processor as follows:
Note, if the supplied Saxon processor is a Saxon HE (Home Edition) processor then there may be compatibility issues if the pipeline uses any filters which in turn use Saxon PE or EE features.
2.3. Converting a DOM document into a Saxon XdmNode tree
We make use of a Saxon processor to convert a W3C DOM document (
doc) from location (
loc) into Saxon XdmNode tree as follows:
2.4. Preparing a DOM destination
We create a Saxon DOM destination as follows:
2.5. Comparing the XdmNode trees
We perform the XML comparison as follows.
2.6. Convert the resulting XdmNode into a DOM document
We create and populate a DOM document as follows:
3. Running the sample
Download the sample from https://bitbucket.org/deltaxml/using-w3c-dom.
The sample resources need to be checked-out, cloned or downloaded and unzipped into the samples directory of the XML Compare release. The resources should be located such that they are two levels below the top level release directory, for example DeltaXML-XML-Compare-10_0_0_j/samples/usingDOM
Details of how to run the sample are given in README.md, displayed in Bitbucket under the list of source files.
4. Further Details
See the commentary in the UsingDOM.java source file.