使用xPath 根据路径解析文件.
xpath 具有多个版本。java,c/++,python 目前都用
、
xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<reportSizeInterval>5000000</reportSizeInterval>
<databaseServiceClientProxy>http://127.0.0.1:8089/RPC/databaseService</databaseServiceClientProxy>
</root>
final String confFile = "conf/wget.xml";
try {
builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(confFile));
XPathFactory xpfactory = XPathFactory.newInstance();
XPath path = xpfactory.newXPath();
long reportSizeInterval = Long.parseLong(path.evaluate("/root/reportSizeInterval", doc));
if (reportSizeInterval < 1024 * 1024) {
reportSizeInterval = (1024 * 1024);
}
Downloader.setReportSizeInterval(reportSizeInterval);
databaseServiceClientProxy = path.evaluate("/root/databaseServiceClientProxy", doc);
xpath 具有多个版本。java,c/++,python 目前都用
、
xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<reportSizeInterval>5000000</reportSizeInterval>
<databaseServiceClientProxy>http://127.0.0.1:8089/RPC/databaseService</databaseServiceClientProxy>
</root>
final String confFile = "conf/wget.xml";
try {
builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(confFile));
XPathFactory xpfactory = XPathFactory.newInstance();
XPath path = xpfactory.newXPath();
long reportSizeInterval = Long.parseLong(path.evaluate("/root/reportSizeInterval", doc));
if (reportSizeInterval < 1024 * 1024) {
reportSizeInterval = (1024 * 1024);
}
Downloader.setReportSizeInterval(reportSizeInterval);
databaseServiceClientProxy = path.evaluate("/root/databaseServiceClientProxy", doc);