Using the XmlDiffPatch Namespace
Since XmlDiffPatch
is a
.NET assembly, it can be included in any .NET project by adding it as
a reference in Visual Studio .NET, or by specifying the
/r:xmldiffpatch.dll
command-line switch to the C#
compiler. If you plan to use XmlDiffPatch
in
multiple projects, you may find it useful to add it to your Global
Assembly Cache using the installutil
executable or the Microsoft .NET Framework Configuration
tool.
Once
you’ve added the XmlDiffPatch
reference to your project or Makefile, you can include it in your own
source code with the using statement:
using Microsoft.XmlDiffPatch;
Example 13-1 shows a program which constructs two
XmlDocument
instances in memory, then compares
them using XmlDiff
.
using System; using System.Text; using System.Xml; using Microsoft.XmlDiffPatch; public class DoDiff { public static void Main(string [ ] args) { XmlDocument doc1 = new XmlDocument( ); doc1.AppendChild(doc1.CreateXmlDeclaration("1.0", null, null)); doc1.AppendChild(doc1.CreateElement("foo")); XmlDocument doc2 = new XmlDocument( ); doc2.AppendChild(doc2.CreateXmlDeclaration("1.0", null, null)); doc2.AppendChild(doc2.CreateElement("bar")); doc2.DocumentElement.AppendChild(doc2.CreateElement("baz")); XmlTextWriter diffgram = new XmlTextWriter(Console.Out); diffgram.Formatting = Formatting.Indented; XmlDiff diff = new XmlDiff(XmlDiffOptions.None); diff.Compare(doc1, doc2, diffgram); diffgram.Flush( ...
Get .NET & XML now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.