> ## Content Index
> Fetch the complete content index at: https://www.workroom-productions.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Diff Tool Exercises
- URL: https://www.workroom-productions.com/diff-tool-exercises/
- Published: 2025-01-07T11:21:06.000Z
- Updated: 2025-02-05T19:22:49.000Z
- Description: Play with `diff` – solutions available.
- Author: James Lyndsay
- Tags: Exercises

`diff` compares two files, highlighting differences. Here's [how diff can work for testers](https://www.workroom-productions.com/diff-for-testers/). On that page, you'll find links to several tools that implement and build on `diff` – you may already have your own preference.

In this exercise, you’ll use any diff tool that seems right to you.

This exercise is more fun in a group. If you’re in a group, please talk about what tool you’d use. Perhaps re-run the exercise with someone else’s tool of choice, or with someone else.

The solutions are below. The tool will do most of the work – give yourself kudos for spotting non-trivial things. Zero kudos if you look at the solutions before trying the exercises.

## Exercises Group 1 – XML and JSON

Download the linked files, use them in a tool. 

If you’re opening the file in a browser, finding out what an xmlschema is, and reading through it, you’re doing it …differently from how I’d expect you to do it.

### Exercise 1.01 (XML)

[file 1](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.1/pain.008.001.01v1.xsd), [file 2](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.1/pain.008.001.01v2.xsd)

#### Solution

#### Exercise 1.01 - Lines Removed

in the schema definition, v2 is missing these lines, location 453 in original

```
<xs:element name="BkPtyId" type="Max35Text" minOccurs="0" maxOccurs="1"/>
<xs:element name="TaxIdNb" type="Max35Text" minOccurs="0" maxOccurs="1"/>

```

### Exercise 1.02 (XML)

[file 1](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.2/pain.008.001.01v1.xsd), [file 2](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.2/pain.008.001.01v2.xsd)

#### Solution

#### Exercise 1.02 - Lines Added

In the schema definition, v2 has had line 699 duplicated in error

```
</xs:complexType>
```

### Exercise 1.03 (XML)

[file 1](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.3/pain.008.001.01v1.xsd), [file 2](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.3/pain.008.001.01v2.xsd)

#### Solution

#### Exercise 1.03 - Lines Rearranged

In the schema definintion on lines 224 to 234 of v2, SimpleType DocumentType2Code has been rearranged. Kudos if you recognised that it has been sorted

```
<xs:enumeration value="CINV"/>
<xs:enumeration value="CMCN"/>
<xs:enumeration value="CNFA"/>
<xs:enumeration value="CREN"/>
<xs:enumeration value="DEBN"/>
<xs:enumeration value="DISP"/>
<xs:enumeration value="DNFA"/>
<xs:enumeration value="HIRI"/>
<xs:enumeration value="MSIN"/>
<xs:enumeration value="SBIN"/>
<xs:enumeration value="SOAC"/>

```

### Exercise 1.04 (XML)

[file 1](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.4/pain.008.001.01v1.xsd), [file 2](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.4/pain.008.001.01v2.xsd)

#### Solution

#### Exercise 1.04 Information Changed On A Single Line

In the schema definition on line 463, the order of attributes has been rearranged. Kudos if you noticed that `maxOccurs` has changed from 4 to 5

```
<xs:element name="PrvtId" minOccurs="1" maxOccurs="5" type="PersonIdentification3" />

```

### Exercise 1.05 (XML)

[file 1](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.5/pain.008.001.01v1.xsd), [file 2](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.5/pain.008.001.01v2.xsd)

#### Solution

#### Exercise 1.05 - Lines Split

In the schema definition on line 165, the line has been split by tag. 

Kudos if you noticed that there’s an extra attribute `base`, that the tag is no longer closed with `/>` but ends with a `>`, and that the `name` attribute is now `ccy` rather than `Ccy`

```
<xs:attribute 
	name="ccy" 
	type="CurrencyCode" 
	base="xs:string"
	use="required">

```

### Exercise 1.06 (XML)

[file 1](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.6/pain.008.001.01v1.xsd), [file 2](http://exercises.workroomprds.com/DiffToolExercise/DiffToolExercise%5F1.6/pain.008.001.01v2.xsd)

#### Solution

#### Exercise 1.06 - Lines Joined

In the schema definition, line 278 has been joined with line 279\. Kudos if you noticed the spelling of `elemnet`, the absence of capitalisation in both pairs of `maxoccurs` and `minoccurs`, and at least one spellign error.

```
<xs:element name="ClrSysMmbId" type="ClearingSystemMemberIdentification3Choice" minoccurs="0" maxoccurs="1"/><xs:elemnet name="Nm" type="Max70Text" minocurrs="0" maxoccurs="1"/>

```

### Exercise 1.07 (JSON)

[file 1](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F1%5Fa.json), [file 2](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F1%5Fb.json)

#### Solution

#### Exercise 1.07 - data changed

On line 632, the value has an extra decimal place. Kudos if you noticed the small change in property name `entryCustom4OCode`.

```json
"entryCustom4OCode": "20.000000000",
```

On 892, the `cardTransactionReferenceNumber` is `""` rather than `null`. 

```json
"cardTransactionReferenceNumber": "",
```

### Exercise 1.08 (JSON)

[file 1](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F2%5Fa.json), [file 2](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F2%5Fb.json)

#### Solution

#### Exercise 1.08 - line added

Line 346 in the second file does not exist in the first file.

```json
"nextPage": null
```

Kudos if you noticed that it is missing the trailing comma, making the JSON invalid.

### Exercise 1.09 (JSON)

[file 1](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F3%5Fa.json), [file 2](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F3%5Fb.json)

#### Solution

#### Exercise 1.09 - lines missing

Line 46-48 , 67-69, 126-128 and 298-300 in the first are missing in the second.

```json
          "employeeCustom19Code": null,
          "employeeCustom20Code": null,
          "employeeCustom21Code": null,

          "employeeCustom19Value": null,
          "employeeCustom20Value": null,
          "employeeCustom21Value": null

          "reportCustom18Code": null,
          "reportCustom19Code": null,
          "reportCustom20Code": null,

          "allocationCustom18Code": null,
          "allocationCustom19Code": null,
          "allocationCustom20Code": null,
```

Kudos if you noticed that line 66 correctly omits the trailing comma, so the JSON is valid although the data is missing. 

Kudos if you wondered why `entryCustomCode` has been left untouched.

### Exercise 1.10 (JSON)

[file 1](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F4%5Fa.json), [file 2](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F4%5Fb.json), [file 2b](https://exercises.workroomprds.com/DiffToolExercise/DiffToolMoreEx1/transaction%5F4%5Fb2.json)

Why have I given you two file 2s? Can you see any differences?

#### Solution

#### Exercise 1.10 - values changed, alternative formats

The second file has a new blank line at line 71

The second document status is marked "Pending" rather than "READY" on line 358

```json
                "docStatus": "Pending"
```

Kudos if you wondered why `Pending` is not in upper case.

Kudos if you spotted that while file1 and file 2 have identical *contents*, they are rather different *sizes*. More kudos if you noticed their *encoding* is different. 

```shell
-rw-r--r--@  1 james  staff   14617 10 Jan 11:14 transaction_4_a.json
-rw-r--r--@  1 james  staff   14628 10 Jan 11:25 transaction_4_b.json
-rw-r--r--@  1 james  staff   29254 10 Jan 11:25 transaction_4_b2.json

james@Mac diff tool exercise % file -I transaction_4_b.json 
transaction_4_b.json: text/plain; charset=utf-8
james@Mac diff tool exercise % file -I transaction_4_b2.json
transaction_4_b2.json: text/plain; charset=utf-16be
```

Your tool may not reveal this to you... 

[How various git diff viewers represent file encoding changes in pull requests - The Old New ThingThe invisible UTF-8 BOM, and sometimes invisible encoding changes.![](https://storage.ghost.io/c/7e/30/7e30843b-2abb-494a-ab80-0e931d8ae9a9/content/images/icon/Microsoft-Favicon.png)The Old New ThingRaymond Chen![](https://storage.ghost.io/c/7e/30/7e30843b-2abb-494a-ab80-0e931d8ae9a9/content/images/thumbnail/ShowCover.jpg)](https://devblogs.microsoft.com/oldnewthing/20241230-00/?p=110692)

«JL: Add more, in CSV and TXT (i.e. dir list). »

Planned exercises include...

## Exercises Group 2 – Code and config

Python, JavaScript, YAML/TOML, env

## Exercises Group 3 – Markdown

Docs and readme.

## Exercises Group 3 – Folders

Changed content, added / removed, renamed / moved, timestamp, permissions, ?encoding, ?os-specific metadata, ?hash, 

## Exercises Group 4 – Combos

sort / grep / filter – first, within git and across files for a commit, on directory / process lists, getting unique / count of changes, 

## 

---

*This page is a work in progress. I'm sure that a curious reader can easily find my notes to myself. «JL: perhaps, if the script finds any notes, it can insert this message?»*