Compare Method (XmlNode, XmlNode, XmlWriter)

Microsoft XML Diff

Microsoft XML Diff 1.0 and XML Patch 1.0

XmlDiff.Compare Method (XmlNode, XmlNode, XmlWriter)

Performs a comparison of XML nodes and outputs an XDL Diffgram describing the differences.

[Visual Basic]
Overloads Public Function Compare( _
  ByVal sourceNode As XmlNode, _
  ByVal changedNode As XmlNode, _
  ByVal diffgramWriter As XmlWriter _
) As Boolean
[C#]
public Boolean Compare(
  XmlNode sourceNode,
  XmlNode changedNode,
  XmlWriter diffgramWriter
);

Parameters

sourceFile
An XmlNode containing the original source node to be used in the comparison.
changedFile
An XmlNode containing the changed node to be used in the comparison.
diffgramWriter
The XmlWriter to which you want to output the XDL Diffgram.

Remarks

The types of nodes that can be passed into the Compare method are any combination of the following:

  • XmlDocument
  • XmlElement
  • XmlText
  • XmlCDataSection
  • XmlEntityReference
  • XmlComment
  • XmlDocumentType
  • XmlProcessingInstruction

The Compare method cannot be used to compare XmlAttribute, XmlEntity, or XmlNotation node types.

Example

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

Namespace TestCompare
   Class Class1
      
      Shared Sub Main()
         Dim sourceDoc As New XmlDocument()
         sourceDoc.Load("source.xml")
         Dim changedDoc As New XmlDocument()
         sourceDoc.Load("changed.xml")
         Dim diffgramWriter = New XmlTextWriter("testdiff.xml", New System.Text.UnicodeEncoding())
         Dim xmlDiff As New XmlDiff()
         Dim bSame As Boolean = xmlDiff.Compare(sourceDoc, changedDoc, diffgramWriter)
         diffgramWriter.Flush()
         diffgramWriter.Close()
      End Sub
   End Class
End Namespace
[C#]
using System;
using System.Xml;
using Microsoft.XmlDiffPatch;
namespace TestCompare
{
  class Class1
    {
        static void Main()
            {
                XmlDocument sourceDoc = new XmlDocument();
                sourceDoc.Load("source.xml");
                XmlDocument changedDoc = new XmlDocument();
                sourceDoc.Load("changed.xml");
                XmlWriter diffgramWriter = new XmlTextWriter("testdiff.xml", new System.Text.UnicodeEncoding());
                XmlDiff xmlDiff = new XmlDiff();
                bool bSame = xmlDiff.Compare(sourceDoc, changedDoc, diffgramWriter);
                diffgramWriter.Flush();
                diffgramWriter.Close();
            }
    }
}

For information on running the code samples, see Running XmlDiff and XmlPatch Class Code Samples.

Requirements

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

See Also

XmlDiff Class | XmlDiff Members | Microsoft.XmlDiffPatch

© 2002 Microsoft Corporation. All rights reserved.