How can I read diffgram file generated by XmlDiff.Compare()

元气小坏坏 提交于 2019-12-05 22:36:17

You can consume your diffgram in XmlDiffView class. But for me it doesn't work perfectly. It highlights the difference but also shows that I deleted some nodes and added new.

XmlDiffView dv = new XmlDiffView();
//Load the original file again and the diff file.
XmlTextReader orig = new XmlTextReader("F:\\XML_1.xml");
        XmlTextReader diffGram = new XmlTextReader("F:\\diff.xml");
        dv.Load(orig,
            diffGram);

        //Wrap the HTML file with necessary html and 
        //body tags and prepare it before passing it to the GetHtml method.

        string tempFile =  "F:\\diff" +r.Next() + ".htm";
        StreamWriter sw1 = new StreamWriter(tempFile);
        sw1.Write("<html><body><table width='100%'>");
        //Write Legend.
        sw1.Write("<tr><td colspan='2' align='center'><b>Legend:</b> <font style='background-color: yellow'" +
            " color='black'>added</font>&nbsp;&nbsp;<font style='background-color: red'" +
            " color='black'>removed</font>&nbsp;&nbsp;<font style='background-color: " +
            "lightgreen' color='black'>changed</font>&nbsp;&nbsp;" +
            "<font style='background-color: red' color='blue'>moved from</font>" +
            "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>moved to" +
            "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>" +
            "ignored</font></td></tr>");

        dv.GetHtml(sw1);
        sw1.Write("</table></body></html>");
        sw1.Close();
        dv = null;
        orig.Close();
        diffGram.Close();

I ran this using your xml files and they are equal. When I modified the value CommandString from ABC to ABCD I got highligted changed value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!