0

我想了解两个 HTML 字符串之间的差异(删除字符串和添加字符串)。diff 函数的函数必须给出如下结果:

String html1 = "<h1>foo foo </h1>";
String html2 = "<h1>foo baar </h1>";

private String diff(String html1, String html2){
 ...
// diff method should return following:
return "<h1>foo <span class = "deleted">foo</span> <span class = "added">baar </span> </h1>";
}

我试过 diff_match_patch 但它有 html 标签的问题。例子:

String html1 = "<ol><li>foo</li><li>baar</li></ol>" 
String html2 = "<ol><li>AA</li></ol>"

diff_match_patch(html1, html2) gives the following diff string:

<ol>
<li>AA<del style="background:#ffe6e6;"></li>
<li>BB</del>
</li>
</ol>

它应该是:

<ol>
<li>AA</li>
<del style="background:#ffe6e6;"><li>BB</del>
</li>
</ol>
4

1 回答 1

0

即使您说它们是 Html 字符串,但对于 java,它们就像任何其他正常的一样String

尝试

    private String diff(String html1, String html2){

    // trim the string and null checks ..etc
    if(html1.equalsIgnoreCase(html2)){

     //  string  are same 
     }

    else {
      // they are different.
  }


    }
于 2013-08-30T07:14:58.147 回答