Subtree Processing Mode Overview
This section introduces the Subtree Processing Mode. The sample resources including how to set up this feature can be found here.
This section describes and discusses how different content in a set of inputs can be compared as either Data or Text in a customisable way to achieve better results.
What is Subtree Processing?
Previously, DeltaNova users could not effectively extend or use our Data processing features on Text within Documents, or Text processing features in Data. However sometimes files are a mix of Text content and Data. In order to improve the performance, some content needs to be marked as a Data section to be treated appropriately, and vice versa.
The Subtree Processing feature allows sections to be compared with their appropriate content type. This improves performance and helps DeltaNova Compare provide better results.
What is Data vs Text?
A simple way to view Data vs Text is to imagine the main purpose. Text is designed for a human to read it (e.g. content in a book or article) vs Data being something more inclined to be storage of data (e.g. a list of contacts or technical specifications).
There is no true definition for Data or Text in XML. However, for deciding how to use Subtree Processing best, you can use the following decision points to help understand whether content should be marked as text or data:
-
The leaf content of Data is more likely to be short, consisting of fewer or single words contained within an element which describes its meaning. Other data elements are structures built up from these leaf elements, and they are often repeated. For data, attributes are often used to store name/value data pairs and are critical to the meaning.
-
Text can be considered as content which consists of more than 5 words, contains tables, or contains mixed content (i.e. when text and elements appear adjacent to one another within the same parent element). For text content, attributes are often used for supplementary information such as display colour or text style.
See the examples in the Subtree Processing Mode Configuration section, or the Bitbucket sample, for a demonstration of Data and Text content being compared with their respective processing types, and further discussion.
Subtree Processing Mode Configuration
Text content processing aligns elements based on the text content of the elements, taking into account the order of the words within the text. Data content processing aligns elements considering the attributes as name/value pairs and the unique words within the text content of the element (but not their order).
Subtree Processing Mode
To set the default Subtree Processing mode for a comparison using the Java API:
SubtreeProcessingMode subtreeProcessingMode = new SubtreeProcessingMode(SubtreeType.TEXT);
DocumentComparator dc = new DocumentComparator();
dc.setSubtreeProcessingMode(subtreeProcessingMode);
dc.compare(in1, in2, result);
Text
Text Content Processing is the default Subtree Processing Mode for XML Compare. It is better for XML files containing Text or that can be considered as Documents.
SubtreeProcessingMode subtreeProcessingMode = new SubtreeProcessingMode(SubtreeType.TEXT);
Data
Data Content Processing can be enabled as the default for a comparison using the following initialisation of the SubtreeProcessingMode:
SubtreeProcessingMode subtreeProcessingMode = new SubtreeProcessingMode(SubtreeType.DATA);
Setting Subtree Processing Mode on Subtrees
When working with mixed content, a set of inputs may contain both Data and Text content. A Subtree consists of an XPath and a type — an XPath to an element which will then be compared with the relevant processing type.
To add Subtrees using the Java API:
List<Subtree> subtrees = new ArrayList<>();
Subtree subtree = new Subtree("p", SubtreeType.TEXT);
subtrees.add(subtree);
SubtreeProcessingMode subtreeProcessingMode = new SubtreeProcessingMode(subtrees);
DocumentComparator dc = new DocumentComparator();
dc.setSubtreeProcessingMode(subtreeProcessingMode);
dc.compare(in1, in2, result);
Ordered/Unordered Comparison within a Subtree
SubtreeProcessingMode also allows for ordered or unordered comparisons within subtrees. Subtrees will need to have an additional ordered value specified:
DocumentComparator dc = new DocumentComparator();
List<Subtree> subtrees = new ArrayList<>();
Subtree subtree = new Subtree("addressList", false);
subtrees.add(subtree);
SubtreeProcessingMode subtreeProcessingMode = new SubtreeProcessingMode(subtrees);
dc.setSubtreeProcessingMode(subtreeProcessingMode);
dc.compare(f1, f2, result);
Alternatively, this can be set within DCP:
<standardConfig>
<subtreeProcessingMode>
<subtrees>
<subtree elemXpath="addressList" ordered="false"/>
</subtrees>
</subtreeProcessingMode>
</standardConfig>
Using Keys
To detect changes in sets or orderless elements, keys help XML Compare perform correlation. See Using Keys with Ordered Data for more details.
DocumentComparator dc = new DocumentComparator();
List<ChildAlignment> childAlignmentList = new ArrayList<>();
List<Subtree> subtrees = new ArrayList<>();
ChildAlignment alignment = new ChildAlignment("person", "@customerid");
childAlignmentList.add(alignment);
Subtree subtree = new Subtree("addressList", false, childAlignmentList);
subtrees.add(subtree);
SubtreeProcessingMode subtreeProcessingMode = new SubtreeProcessingMode(subtrees);
dc.setSubtreeProcessingMode(subtreeProcessingMode);
dc.compare(f1, f2, result);
Using Namespaces When Providing XPaths
When providing an XPath as part of the subtree processing mode configuration, it is often useful to be able to use node names that contain an XML namespace prefix. For more information on how to configure this, see Using Namespaces Within XPath Expressions.