Skip to main content
Skip table of contents

Formatting Elements With Rule Processing Sample

Introduction

XML Merge allows users to mark elements in the XML inputs as formatting elements. For these elements, the merge operation can focus on textual changes rather than structural changes. For further information, see Formatting Elements Sample and different representations for formatting element changes. XML Merge also provides capability to automatically resolve the simple changes by applying rule processing. For more information about rule processing, see Rule processing guide.

This sample aims to demonstrate the behaviour of formatting elements when rule processing is enabled.

Applying rules to formatting elements

When the rule processing is enabled, XML Merge accepts simple adds, deletes and modification. All of these rules are applied to attributes, elements and their contents. However, when it comes to formatting elements, the rule processing is applied to formatting element tags instead of their contents. The formatting elements tags are usually added or deleted around the content in the inputs. This means that that there is no possibility of modification or conflict in case of formatting element tag changes. So we can categorise formatting element tags changes as:

  1. Addition of formatting element tags : When rule processing is enabled, the addition is accepted. In other words, the formatting tags are resolved and kept in the result.

  2. Deletion of formatting element tags : When rule processing is enabled, the deletion is accepted. In other words, the formatting tags are removed.

  3. Addition of formatting element introducing an overlap: If a document version adds a formatting element which introduces an overlap with another formatting element from other document version, then it is not considered as a simple change. These kind of changes are not resolved during rule processing.

The default behaviour of rule processing which accepts simple adds and deletes can be changed by using methods setDisplaySimpleAdds and setDisplaySimpleDeletes on the RuleConfiguration object. The method setDisplayChangesInvolving can be used with formatting elements to show added or deleted formatting elements by a particular version. Also, a method setDisplayFormatChangesIn can be used to show formatting changes inside an element.

Example

To illustrate how XML Merge works with formatting elements when rule processing is enabled, we will examine the following three versions, 'A', 'B' and 'C' of a simple document. Where 'A' is the common ancestor. In the following versions, the 'bold' formatting has been added in the first para by 'B' and 'C', whereas 'italic' formatting has been deleted by 'C' in the second para.

A
XML
<document>
  <para>Example of formatting addition around the word.</para>
  <para>Example of formatting deletion around the <italic>word</italic>.</para>
</document>
B
XML
<document>
  <para>Example of formatting addition around the <bold>word</bold>.</para>>
  <para>Example of formatting deletion around the <italic>word</italic>.</para>
</document>
C
XML
<document>
  <para>Example of formatting addition around the <bold>word</bold>.</para>
  <para>Example of formatting deletion around the word.</para>
</document>

Results

The following result is generated with rule processing disabled.

DeltaV2.1 Result
XML
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A!=B!=C">
    <para deltaxml:deltaV2="A!=B=C">Example of formatting addition around the <bold deltaxml:deltaTag="B,C" deltaxml:deltaV2="A!=B=C">word</bold>.</para>
    <para deltaxml:deltaV2="A=B!=C">Example of formatting deletion around the <italic deltaxml:deltaTag="A,B" deltaxml:deltaV2="A=B!=C">word</italic>.</para>
</document>

The following result is generated with rule processing enabled. In this result, the added 'bold' element has been accepted and deleted 'italic' element has been removed.

Rule Processed DeltaV2.1 Result
XML
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A=B=C">
    <para>Example of formatting addition around the <bold>word</bold>.</para>
    <para>Example of formatting deletion around the word.</para>
</document>

The following result is also generated with rule processing enabled. But this time the displayChangesInvolving property is set to 'B'. In this result, the addition of 'bold' element is not resolved as it involves B, however the deletion of 'italic' element (which involves 'C') is resolved.

Rule Processed DeltaV2.1 Result- Display Changes Involving Version B
XML
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A!=B=C">
    <para deltaxml:deltaV2="A!=B=C">Example of formatting addition around the <bold deltaxml:deltaTag="B,C" deltaxml:deltaV2="A!=B=C">word</bold>.</para>
    <para deltaxml:deltaV2="A=B=C">Example of formatting deletion around the word.</para>
</document>

The following result is also generated with rule processing enabled, but this time the displayFormatChangesIn property is set to the XPath '//para' which selects all 'para' elements in the XML. The result therefore displays the changes to formatting elements with all para elements.

Extracting DeltaV2.1 format output with rule processing - Display Formatting Changes In all 'para'
XML
<document deltaxml:version-order="A, B, C" deltaxml:version="2.1" deltaxml:deltaV2="A!=B!=C">
	<para deltaxml:deltaV2="A!=B=C">Example of formatting addition around the <bold deltaxml:deltaTag="B,C" deltaxml:deltaV2="A!=B=C">word</bold>.</para>
	<para deltaxml:deltaV2="A=B!=C">Example of formatting deletion around the <italic deltaxml:deltaTag="A,B" deltaxml:deltaV2="A=B!=C">word</italic>.</para>
</document>

Implementation

The sample is implemented in the main method of a single Java class, FormattingElementsWithRuleProcessing.java. This class contains comments and System.out message text that explains usage of the XML Merge Java API for this sample.

Running the Sample

To run this sample, all the files you need together with instructions are available on Bitbucket

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.