Altova DiffDog Server 2024 

When comparing files in text mode, you can view the comparison result in either text or XML format. To understand how DiffDog Server reports differences between text files, let's assume that the following two text files must be compared side-by-side.

 

apples

peaches

grape

bananas

strawberries

apples

nuts

peaches

grapes

bananas

file1.txt

file2.txt

 

Note:The files used in this example are text files with .txt extension; however, they can be any other non-binary file kinds, such as .html, .json, .js, .cs, and so on.

 

When compared with a graphical differencing tool like DiffDog, the differences between the two files are represented as shown below. As shown below, there are three differences in total: one line was added, one was changed, and one was deleted.

dds_text_report

DiffDog comparison report

In DiffDog Server, you can compare these two files with the command:

 

<executable> diff file1.txt file2.txt --mode=text --output-mode=text --output-file=report.txt

 

Note:The --mode option instructs the program to treat the compared files as text (not as XML or binary). The --output-mode option lets you specify the format the comparison report (text or XML).

 

In the text report produced after running the comparison, the differences are reported as follows:

 

1a2

> nuts

3c4

< grape

---

> grapes

5d5

< strawberries

DiffDog Server comparison report (text)

In the report above, "a" indicates an addition, "c" indicates a change, and "d" indicates a deletion. The character ">" points to the right side of the comparison. "<" points to the left side of the comparison. The results must be understood as instructions that one would need to follow in order to make both files equal, namely:

 

1a2 means "After line 1 in the left file, add some text to make it equal with line 2 from the right file". The next line shows the exact text to be added, in this case, the text "nuts" from the right file.

3c4 means "Replace line 3 from the left file with line 4 from the right file". The next lines shows the relevant content from both files, separated by "---".

5d5 means "Delete line 5 of the left file to make it equal with the line 5 from the right file". The next line shows exactly the text to be deleted (in this case, "strawberries").

 

XML report

You can also compare the same two files and get the report as XML file, by running the command:

 

<executable> diff file1.txt file2.txt --mode=text --output-mode=xml --output-file=report.xml

 

In you choose XML as reporting format, then the same report is represented as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Differencing export generated by Altova DiffDog Server -->
<diff_result>
  <diff_info comparison_mode="text">
    <source_left name="c:\file1.txt" uri="file:///c:/file1.txt"/>
    <source_right name="c:\file2.txt" uri="file:///c:/file2.txt"/>
  </diff_info>
  <text_diff left_location="1" right_location="2">
    <right_content>
        <line>nuts</line>
    </right_content>
  </text_diff>
  <text_diff left_location="3" right_location="4">
    <left_content>
        <line>grape</line>
    </left_content>
    <right_content>
        <line>grapes</line>
    </right_content>
  </text_diff>
  <text_diff left_location="5" right_location="5">
    <left_content>
        <line>strawberries</line>
    </left_content>
  </text_diff>
</diff_result>

DiffDog Server comparison report (XML)

In the XML report above, there is a diff_info element at the very top. The diff_info element supplies information about files that were compared (including the comparison mode used, and the path of the compared files). This element occurs only once.  The comparison_mode attribute indicates what was the value of the --mode option when running the comparison; this is also useful if you need to know the default comparison mode used by DiffDog Server when no --mode option was specified at the command line.

 

Next, the same three differences are listed as in the text report. The information about the differences involved is presented with the help of the left_location and right_location attributes, while the actual content is enclosed within left_content or right_content elements. In this example, each location is a line. However, a location is not always a single line; it can consist of multiple lines in some cases—in such cases there would be multiple consecutive line elements in the report.

© 2017-2023 Altova GmbH