0
我想獲得兩個HTML字符串之間的差異(字符串被刪除並添加了字符串)。 diff函數的功能必須給出如下結果:獲取兩個html字符串之間的差異
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>
你可以嘗試考慮看看【JAVA的Diff-utils的(https://code.google.com/p/java-diff-utils/) – MadProgrammer
@ØHankyPankyØ編後 –
答案應該是「替換