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