java - Displaying Difference of an XML file in HTML format -
i working on code show differences in 2 files in html format .i doing in java . have done far . 1. reading file contents string arrays . 2. using lcs algorithm find longest sub sequence matrix mentioned here 3. utilize string builder create html head 4. using lcs matrix , append strings string buffer. 5. if there difference in 2 strings alter tr bgcolour show in different color.
this works fine when utilize normal text file .
code snippet :
sb.append("<tr bgcolor='#ff0000'>"); sb.append("<td>"); sb.append( x[i++]); sb.append("</td>"); sb.append("<td>"); sb.append( y[j++]); sb.append("</td>"); sb.append("</tr>");
but if diff between 2 xml files not able see contents.
if text normal , html formed :
<td>normaltext</td>
//rendered properly
if xml files contains
<hello>
tag html formed contains
<td><hello></td>
because of browser not able render properly.
how can resolve ? pointers helpful.
replace <
<
, >
>
problem solved.
to more concrete in case, next :
sb.append("<tr bgcolor='#ff0000'>"); sb.append("<td>"); sb.append( x[i++].replaceall("<", "<").replaceall(">", ">")); sb.append("</td>"); sb.append("<td>"); sb.append( y[j++].replaceall("<", "<").replaceall(">", ">")); sb.append("</td>"); sb.append("</tr>");
according comment, improve :
sb.append("<tr bgcolor='#ff0000'>"); sb.append("<td>"); sb.append( x[i++].replaceall("&", "&").replaceall("<", "<").replaceall(">", ">")); sb.append("</td>"); sb.append("<td>"); sb.append( y[j++].replaceall("&", "&").replaceall("<", "<").replaceall(">", ">")); sb.append("</td>"); sb.append("</tr>");
to have <= , >= not replaced, working solution, little nasty :) :
string x = "<hello>&<=<blabbalal>"; system.out.println(x.replaceall("&", "&").replaceall("<", "<").replaceall(">", ">").replaceall(">=", ">=").replaceall("<=", "<="));
has output :
<hello>&<=<blabbalal>
java html xml
No comments:
Post a Comment