XmlDiffAlgorithm Enumeration

Microsoft XML Diff

Microsoft XML Diff 1.0 and XML Patch 1.0

XmlDiffAlgorithm Enumeration

Specifies which algorithm to use when comparing XML documents.

[Visual Basic]
Public property Algorithm(ByVal value As XmlDiffAlgorithm)
[C#]
public XmlDiffAlborithm Algorithm {get; set;}

Members

Member name Description
Auto Default. Chooses the comparison algorithm for you depending on the size and assumed number of changes in the compared documents.
Fast Compares the two XML documents by traversing the XML tree and comparing it node-by-node. This algorithm is very fast but may produce less precise results. For example it may detect an add and remove operation on a node instead of a move operation.
Precise Is based on an algorithm for finding editing distance between trees, also known as Zhang-Shasha algorithm. This algorithm gives very precise results but it may be very slow on large XML documents with many changes.

Example

[Visual Basic]
Imports System
Imports System.Xml
Imports Microsoft.XmlDiffPatch

Namespace TestCompare
   Class Class1
      Shared Sub Main()
        Dim diffWriter = New XmlTextWriter("diffgram.xml", New System.Text.UnicodeEncoding())
        Dim myDiff As New XmlDiff()
        myDiff.Algorithm = XmlDiffAlgorithm.Precise
        Dim bSame As Boolean = myDiff.Compare("source.xml", "changed.xml", False, diffWriter)
        Console.WriteLine("The answer is {0} ", bSame)
      End Sub       'Main
   End Class       'Class1
End Namespace       'TestCompare  
[C#]
using System;
using System.Xml;
using Microsoft.XmlDiffPatch;

namespace TestCompare
{
  class Class1
    {
        static void Main()
            {
            XmlWriter diffWriter = new XmlTextWriter("diffgram.xml", new System.Text.UnicodeEncoding()); 
            XmlDiff myDiff = new XmlDiff();
            myDiff.Algorithm = XmlDiffAlgorithm.Precise;
            bool bSame = myDiff.Compare("source.xml", "changed.xml", false, diffWriter);
    Console.WriteLine("The answer is {0} ", bSame);

            }
    }
}

Remarks

To select the comparison algorithm you want to use, set the Algorithm property of the XmlDiff class before calling the Compare method. The default value of this property is XmlDiffAlgorithm.Auto, which means the comparison algorithm will be automatically selected depending on the size and assumed number of changes in the compared documents.

Requirements

Namespace: Microsoft.XmlDiffPatch

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP, Windows .NET Server

Assembly: Microsoft.XmlDiffPatch (in XmlDiffPatch.dll)

See Also

Microsoft.XmlDiffPatch | Microsoft XML Diff 1.0 | Microsoft XML Patch 1.0

© 2002 Microsoft Corporation. All rights reserved.