Compare Method (XmlNode, XmlNode)

Microsoft XML Diff

Microsoft XML Diff 1.0 and XML Patch 1.0

XmlDiff.Compare Method (XmlNode, XmlNode)

Performs a comparison of XML nodes.

[Visual Basic]
Overloads Public Function Compare( _
  ByVal sourceNode As XmlNode, _
  ByVal changedNode As XmlNode _
) As Boolean
public Boolean Compare(
  XmlNode sourceNode,
  XmlNode changedNode


An XmlNode containing the original source node to be used in the comparison.
An XmlNode containing the changed node to be used in the comparison.


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.


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

Namespace TestCompare
   Class Class1
      Shared Sub Main()
         Dim sourceDoc As New XmlDocument()
         Dim changedDoc As New XmlDocument()
         Dim xmlDiff As New XmlDiff()
         Dim bSame As Boolean = xmlDiff.Compare(sourceDoc, changedDoc)
         Console.WriteLine("The answer is {0} ", bSame)
      End Sub
   End Class
End Namespace 
using System;
using System.Xml;
using Microsoft.XmlDiffPatch;

namespace TestCompare
  class Class1
        static void Main()
                XmlDocument sourceDoc = new XmlDocument();
                XmlDocument changedDoc = new XmlDocument();
                XmlDiff xmlDiff = new XmlDiff();
                bool bSame = xmlDiff.Compare(sourceDoc, changedDoc);
                Console.WriteLine("The answer is " + bSame);

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


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.