67,513
社区成员
发帖
与我相关
我的任务
分享
<textClip fill="black" font-family="Arial" font-size="14" height="122" id="textClip" width="220" x="12" xml:space="preserve" y="178">
<tbreak/>
老将杨威眼里噙着泪,小鹏一边挥<tbreak/>
手脸上绽放出了笑容,视线却早已<tbreak/>
模糊,肖钦不顾镁光灯的闪烁,右<tbreak/>
手擦拭着眼睛,陈一冰、黄旭也都<tbreak/>
红了眼眶,邹凯眼睛本来就小,此<tbreak/>
时却已星光点点。<tbreak/>
<tbreak/>
</textClip>
public static boolean doc2XmlFile(Document document, String filename) {
boolean flag = true;
try {
/** 将document中的内容写入文件中 */
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
/** 编码 */
// transformer.setOutputProperty(OutputKeys.ENCODING, "GB2312");
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File(filename));
transformer.transform(source, result);
} catch (Exception ex) {
flag = false;
ex.printStackTrace();
}
return flag;
}
public static Document load(String filename) {
Document document = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(new File(filename));
document.normalize();
} catch (Exception ex) {
ex.printStackTrace();
}
return document;
}
/**
* 内容加上回车符
* @param content
* @return
*/
public static String getContentValue(String content){
int line=content.length()/15;
String value="";
String strr="";
for(int i=0;i<line;i++)
{
strr+=content.substring(15*i,15*(i+1))+"<tbreak/>";
}
if(content.length()%15==0){
value="<tbreak/>"+strr;
}else{
value="<tbreak/>"+strr+content.substring(line*15,content.length());
}
return value;
}
public static void rmpUpdate(String filename,String content) {
Document document = load(filename);
NodeList nl = document.getElementsByTagName("textClip");
for (int i = 0; i < nl.getLength(); i++) {
nl.item(0).getFirstChild().setNodeValue(getContentValue(content));
}
doc2XmlFile(document, filename);
}