資源簡介
用java 通過xml模板生成 xml文件

代碼片段和文件信息
package?eg;
import?java.io.BufferedReader;
import?java.io.File;
import?java.io.FileNotFoundException;
import?java.io.FileReader;
import?java.io.IOException;
import?java.text.MessageFormat;
import?xmltool.template.GetxmlContont;
public?class?Generalxml?{
/**
?*?
?*?@Author:HaoMing(郝明)
?*?@Project_name:weinet
?*?@Full_path:eg.Generalxml.java
?*?@Date:@2014?2014-3-28?上午11:10:08
?*?@Return_type:String
?*?@Desc?:讀取指定的xml模板
?*/
public?static?String?readFileByer(String?filePath)?{
StringBuffer?sb?=?new?StringBuffer();
File?file?=?new?File(filePath);
FileReader?fr?=?null;
try?{
fr?=?new?FileReader(file);
}?catch?(FileNotFoundException?e)?{
e.printStackTrace();
}
BufferedReader?br?=?new?BufferedReader(fr);
String?strLine?=?““;
try?{
while?((strLine?=?br.readLine())?!=?null)?{
sb.append(strLine);
sb.append(“\n“);
}
}?catch?(IOException?e)?{
e.printStackTrace();
}?finally?{
try?{
fr.close();
br.close();
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
return?sb.toString();
}
public?static?void?main(String[]?args)?{
final?String??head?=?“l?version=\“1.0\“?encoding=\“UTF-8\“?standalone=\“no\“?>\n“;
final?String?root_start?=?““;
final?String?root_end?=?“ “;
StringBuffer?sb?=?new?StringBuffer();
sb.append(head);
sb.append(root_start);
MessageFormat?mf?=?new?MessageFormat(GetxmlContont.readFileByer(“src/eg/template.xml“));
sb.append(mf.format(new?object[]?{?“l(fā)ist.jsp“?“get“?“l(fā)ist“?“request_param1|request_param2“}));
sb.append(mf.format(new?object[]?{?“content.jsp“?“post“?“content“?“titlepublisherpublished_calendar“}));
sb.append(root_end);
System.out.println(sb.toString());
// System.out.print(sb.toString().replaceAll(“\n“?““));
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-03-28?11:26??eg\
?????文件????????1881??2014-03-28?11:30??eg\Generalxm
?????文件?????????119??2014-03-28?11:24??eg\template.xm
評(píng)論
共有 條評(píng)論