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
[C#]
public Boolean Compare(
  XmlNode sourceNode,
  XmlNode changedNode
);

Parameters

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

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("target.xml")
         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 
[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("target.xml");
                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.

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.