2 Difference Engine Internals
Egil Hansen редактировал(а) эту страницу 2019-12-26 07:32:22 +00:00

The heart of the library is the HtmlDifferenceEngine class, which goes through the steps illustrated in the activity diagram below to determine if the control nodes is the same as the test nodes.

The HtmlDifferenceEngine class depends on three strategies:

  • Filter strategy, which tells the engine what nodes and attributes to skip during comparison.
  • Matching strategy, which helps the engine match the nodes and attributes that should be compared from the control DOM tree with nodes from the test DOM tree.
  • Compare strategy, which helps the engine compare the matched nodes and attributes.

The strategies, provided to the engine via the IDiffingStrategy interface, are used in the highlighted activities in the diagram below. With those, we can control what nodes and attributes take part in the comparison (filter strategy), how control and test nodes and attributes are matched up for comparison (matching strategy), and finally, how nodes and attributes are determined to be same or different (compare strategy).

It starts with a call to the Compare() and recursively calls itself when nodes have child nodes.

img

The library comes with a bunch of different filters, matchers, and comparers, that you can configure and mix and match with your own, to get the exact diffing experience you want. See the Options/Strategies page for details.