public void DiffMissingNodeTest()
            {
                var node1 = LoadNode("<XML></XML>");
                var node2 = LoadNode("<XML><TEST1/></XML>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff();

                Assert.IsFalse(diff.IgnoreWhitespace);
                var sb = new System.Text.StringBuilder();

                Assert.IsFalse(diff.Compare(node1, node2, CreateWriter(sb)));
                SaveDiff("DiffMissingNodeTest-12", sb);
                Assert.IsFalse(diff.Compare(node2, node1, CreateWriter(sb)));
                SaveDiff("DiffMissingNodeTest-21", sb);
            }
            public void SameNodeEqualTest()
            {
                var node1 = LoadNode("<XML>TEST</XML>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff();

                Assert.IsTrue(diff.Compare(node1, node1));
            }
            public void DiffCommentsEqualTest()
            {
                var node1 = LoadNode("<XML xmlns:foo=\"http://www.opengis.net/ogc\"><!--foo--><foo:test>TEST1</foo:test><foo:test>TEST2</foo:test></XML>");
                var node2 = LoadNode("<XML xmlns:bar=\"http://www.opengis.net/ogc\"><!--bar--><bar:test>TEST2</bar:test><bar:test>TEST1</bar:test></XML>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff(Microsoft.XmlDiffPatch.XmlDiffOptions.IgnorePrefixes | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreChildOrder | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreComments);

                Assert.IsTrue(diff.Compare(node1, node2));
            }
            public void DiffNsPrefixEqualTest()
            {
                var node1 = LoadNode("<XML xmlns:foo=\"http://www.opengis.net/ogc\"><foo:test>TEST</foo:test></XML>");
                var node2 = LoadNode("<XML xmlns:bar=\"http://www.opengis.net/ogc\"><bar:test>TEST</bar:test></XML>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff(Microsoft.XmlDiffPatch.XmlDiffOptions.IgnorePrefixes);

                Assert.IsTrue(diff.Compare(node1, node2));
            }
            public void DiffWhitespaceEqualTest()
            {
                var node1 = LoadNode("<XML><TEST>TEST1</TEST><TEST id=\"id\">TEST1</TEST></XML>");
                var node2 = LoadNode("<XML>\n\t<TEST>TEST1</TEST>\n\t<TEST id = 'id' >\n\t\tTEST1\n\t\t</TEST>\n</XML>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff(Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreWhitespace);

                Assert.IsTrue(diff.Compare(node1, node2));
            }
            public void DiffNamespaceEqualTest()
            {
                var node1 = LoadNode("<WFS_Capabilities xmlns=\"http://www.opengis.net/wfs\" version=\"1.1.0\" ></WFS_Capabilities>");
                var node2 = LoadNode("<wfs:WFS_Capabilities xmlns:wfs=\"http://www.opengis.net/wfs\" version=\"1.1.0\" ></wfs:WFS_Capabilities>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff(Microsoft.XmlDiffPatch.XmlDiffOptions.IgnorePrefixes | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreChildOrder | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreComments | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreXmlDecl);

                Assert.IsTrue(diff.Compare(node1, node2));
            }
            public void DiffNodeEqualTest()
            {
                var xml   = "<XML>TEST</XML>";
                var node1 = LoadNode(xml);
                var node2 = LoadNode(xml);
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff();

                Assert.IsTrue(diff.Compare(node1, node2));
            }
            public void DiffWhitespaceTest()
            {
                var node1 = LoadNode("<XML><TEST1/><TEST2> TEST</TEST2></XML>");
                var node2 = LoadNode("<XML><TEST2>TEST</TEST2><TEST1/></XML>");
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff(Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreChildOrder);

                Assert.IsFalse(diff.IgnoreWhitespace);
                var sb     = new System.Text.StringBuilder();
                var writer = System.Xml.XmlWriter.Create(sb);

                Assert.IsFalse(diff.Compare(node1, node2, writer));
                SaveDiff("DiffWhitespaceTest", sb);
            }
        private void button3_Click(object sender, EventArgs e)
        {
            string xml1 = File.ReadAllText(openFileDialog1.FileName);
            string xml2 = File.ReadAllText(openFileDialog2.FileName);

            XmlReader node1 = XElement.Parse(xml1).CreateReader();
            XmlReader node2 = XElement.Parse(xml2).CreateReader();

            XDocument result = new XDocument();
            XmlWriter writer = result.CreateWriter();

            Microsoft.XmlDiffPatch.XmlDiff diff = new Microsoft.XmlDiffPatch.XmlDiff();
            diff.Compare(node1, node2, writer);
            writer.Flush();
            writer.Close();

            xmlText1.Text = xml1;
            xmlText2.Text = xml2;

            xmlTextDiff.Text = result.Document.ToString();

            foreach (XName name in result.Document.Root.DescendantNodes().OfType <XElement>()
                     .Select(x => x.Name).Distinct())
            {
                int sindex = 0;
                while (sindex < xmlText1.Text.Length)
                {
                    // Console.WriteLine(result.Document.Element(name.LocalName).Value);
                    int windex = xmlText1.Find("Name", sindex, RichTextBoxFinds.None);
                    if (windex != -1)
                    {
                        xmlText1.SelectionStart     = windex;
                        xmlText1.SelectionLength    = name.LocalName.Length;
                        xmlText1.SelectionBackColor = Color.Yellow;
                        xmlText2.SelectionStart     = windex;
                        xmlText2.SelectionLength    = name.LocalName.Length;
                        xmlText2.SelectionBackColor = Color.Yellow;
                    }
                    else
                    {
                        break;
                    }

                    sindex += windex + name.LocalName.Length;
                }
                //Console.WriteLine(name);
            }
        }
            public void DiffWmsEqualTest()
            {
                var node1 = LoadNodeFromRes("wfs.getcaps.model");
                var node2 = LoadNodeFromRes("wfs.getcaps.raw");
                var sb    = new System.Text.StringBuilder();
                var diff  = new Microsoft.XmlDiffPatch.XmlDiff(
                    Microsoft.XmlDiffPatch.XmlDiffOptions.IgnorePrefixes
                    | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreNamespaces
                    | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreChildOrder
                    | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreComments
                    | Microsoft.XmlDiffPatch.XmlDiffOptions.IgnoreXmlDecl);

                if (!diff.Compare(node1, node2, CreateWriter(sb)))
                {
                    SaveDiff("DiffWmsEqualTest", sb);
                    Assert.Fail();
                }
            }