之前写过用xslt解析xml文件显示的文章,当时是把oracle库中clob字段xml格式格式化成xml文件。
现在不用xslt,直接在表格中显示,表格每个单元格对应一个xml节点属性,就需要得到每个xml节点的text值,也就是String格式。
public List detailInfo(String id){
Session session = getSession_reXian();
Userbean userbean = new userbean();
SAXReader saxReader=new SAXReader();
ArrayList ret = new ArrayList();
saxReader.setEncoding("UTF-8");
Document document;
try {
String sql = "select message from user_message_clob where userid = '"+id+"'";
PreparedStatement stmt = session.connection().prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next())
{
Clob clob = (Clob)rs.getObject(1);
String rs1 = ClobToString(clob);
Document dom=DocumentHelper.parseText(rs1);
Element root=dom.getRootElement();
Element data=root.element("ROOTDATA");
Element orderData=data.element("USERDATA");
String accountId=orderData.element("ACCOUNT_ID").getText();
userbean.setUsername(orderData.element("USER_NAME").getText());
......
ret.add(userbean);
}
return ret;
} catch (Exception re) {
re.printStackTrace();
return null;
} finally {
if (session != null) {
session.close();
}
}
}