1、自定義xml裏的內容:此處是我項目裏的需要定義一個插件路徑地址(ps:xml裏書寫規範可百度參考)
report.xml 代碼
<?xml version="1.0" encoding="GB2312"?>
<RESULT>
<VALUE>
<NM>path</NM>
<PATH>D:/soft/SWFTools/pdf2swf.exe</PATH>
</VALUE>
</RESULT>
2、Java裏獲取xml定義的參數
Java代碼
導入包
import java.io.File;
import org.w3c.dom.*;
import javax.xml.parsers.*;
//把swf安裝文件路徑地址配置在report.xml,然後通過Java解析獲取xml裏的內容 by chenez
String xmlpath=request.getSession().getServletContext().getRealPath("/")+"flexpaper/report.xml";
File f=new File(xmlpath);
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse(f);
String swfexepath=doc.getElementsByTagName("PATH").item(0).getFirstChild().getNodeValue();
System.out.println("=======swfexepath========"+swfexepath);
java裏打印輸出的swfpath就是xml裏的D:/soft/SWFTools/pdf2swf.exe