Implementation

This comparer uses XPath-based structural comparison rather than traditional text-based diff algorithms.

This approach provides a significant advantage in correctness when comparing structured XML files, because it focuses on the actual semantic structure, not on how the content is laid out or formatted.

For example, take a look at the image below. A standard diff tool would treat these two documents as different β€” simply because the order or formatting of elements differs β€” even though they are functionally identical.

Drawbacks

One of the drawbacks of XPath is that it can only handle one namespace prefix per mapping. This means the example below will not work if the same prefix is used for multiple namespaces.


            <root xmlns:ex="http://example.com/ns1">

                <ex:element>From ns1</ex:element>

                <nested xmlns:ex="http://example.com/ns2">
                    <ex:element>From ns2</ex:element>
                </nested>
            </root>
        

However, using multiple namespaces is perfectly valid in XML β€” as long as each prefix maps to a unique namespace. You just can’t override the same prefix to another URI.


            <root xmlns:book="http://example.com/book"
                xmlns:movie="http://example.com/movie">
            <book:item>
                <book:title>Hyperion</book:title>
            </book:item>

            <movie:item>
                <movie:title>Inception</movie:title>
            </movie:item>

            <defaultElement>This is in the default namespace</defaultElement>
            </root>
        

Colors

🟩 Green means this text exists here but not in the other document.

πŸŸ₯ Red means the text exists in the other document but is missing here.

Text Node

For text node comparisons, only green highlights will appear β€” indicating text that this document has but the other does not. Red will not be shown for missing text in this case.

An unhandled error has occurred. Reload πŸ—™