把字符串转化为xml(通过dom4j )之后就变成另外一种编码,如果想原样保存到数据库只能通过强制不转码
特别是针对表情的消息体
-
public class Dom4jTest2222 {
-
public static void main(String[] args) throws Exception {
-
//String xml = "11\">";
-
-
String body="11\" pid=\"73972bed-4def-4b3e-b6f2-0713c3ee2b43\">1700测试文本tt\"/>";
-
-
System.out.println(body);
-
-
String txt=body.substring(body.indexOf("1700"), body.indexOf("tt\""));
-
System.out.println(body);
-
txt="<![CDATA["+txt+"]]>";
-
body="<bbs type=\"11\"><txt>"+txt+"</txt></bbs>";
-
//body=body.replaceFirst("<txt cont", "<txt ");
-
//body=body.replaceFirst("tt\"/>", "tt\"/>]]>");
-
System.out.println(body);
-
Document doc = null;
-
try {
-
doc = DocumentHelper.parseText(body);
-
System.out.println();
-
} catch (DocumentException e) {
-
e.printStackTrace();
-
doc = null;
-
}
-
-
if (doc != null) {
-
Element el =(Element) doc.selectSingleNode("bbs/txt");
-
String val=el.getText();
-
System.out.println(val);
-
-
//el.set
-
}
-
/*
-
if (doc != null) {
-
Element el = doc.getRootElement();
-
System.out.println("aid="+el.attributeValue("aid"));
-
System.out.println("type="+el.attributeValue("type"));
-
-
List> lst1 = el.elements();
-
for (Object node : lst1) {
-
System.out.println("" + ((Element) node).getName());
-
}
-
List> lst2 = doc.selectNodes("bbs/img");
-
System.out.println("size=
阅读(1283) | 评论(0) | 转发(0) |