如何在XML中为Place Element生成MD5哈希。我想计算Place Element中的所有属性和值。
<?xml version="1.0" encoding="iso-8859-9"?>
<?hash 73533cd0fa219185648ff9554b065bd3?>
<Place Code="1111" Date="2016-06-18 11:28:58">
<User Name="NAME" Number="1"/>
</Place>
&#13;
//放置元素
Element results = doc.createElement("Place");
doc.appendChild(results);
results.setAttribute("Code", "1111");
results.setAttribute("Date", sdt);
while((rs!=null) && (rs.next())) {
Element row = doc.createElement("User");
results.appendChild(row);
// Attributes
Attr xnumber = doc.createAttribute("Number");
xnumber.setValue(rs.getString("number_db"));
row.setAttributeNode(xnumber);
Attr xname = doc.createAttribute("Name");
xname.setValue(rs.getString("name_db"));
row.setAttributeNode(xname);
}
编辑: MD5代码..
String result = null;
char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(source);
//The result should be one 128 integer
byte temp[] = md.digest();
char str[] = new char[16 * 2];
int k = 0;
for (int i = 0; i < 16; i++) {
byte byte0 = temp[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
result = new String(str);
我使用source = rs.getBytes("name_db");
来表示属性和值,但哈希码不会改变。我该怎么办?