本文翻写自我早年的一篇日志http://www.cnblogs.com/ols/archive/2008/05/02/1179849.html

    早年的那篇日志,主要是讲我的探索过程,而如何在自己的.net程序中加入比较XML的功能,讲得比较少,这里尝试讲一下如何加入这一功能。如果有读者想自己研究,可以参考我原来的那篇日志。

    先来看一下比较XML的效果图

在.net中比较XML

    第一步:准备开发环境,VS2005或更高版本。

    第二步:下载XML notepad 2007,并安装。

    第三步:在XML notepad 2007安装目录下找到xmldiffpatch.dll和XmlDiffPatch.View.dll这两个文件,备用(想起菜谱上的“洗净切丝,备用”)。

    第四步:在自己的.net项目(project)中添加引用,xmldiffpatch.dll和XmlDiffPatch.View.dll,如下图所示

在.net中比较XML

    第五步:下载XML差异与修补工具,打开代码,找到VisualXmlDiff.cs文件,备用。

    第六步:将VisualXmlDiff.cs和VisualXmlDiff.resx添加到项目中。

    第七步:修改VisualXmlDiff.cs文件,主要是解决比较结果的着色问题,找到下面的代码

        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>");

相关文章:

  • 2021-12-15
  • 2022-02-19
  • 2021-11-10
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
相关资源
相似解决方案