【发布时间】:2016-10-07 06:50:31
【问题描述】:
我正在尝试使用 XmlTool 解析 XML 文件,以便能够使用 Velocity 模板中的数据。
但是,关于它的文档都很差,并没有真正提供我需要的信息。
文档位于:https://velocity.apache.org/tools/devel/apidocs/org/apache/velocity/tools/generic/XmlTool.html
我已经试过了:
VelocityContext context = new VelocityContext(page);
EasyFactoryConfiguration config = new EasyFactoryConfiguration();
config.toolbox("application")
.tool("org.apache.velocity.tools.generic.XmlTool")
.property("safeMode", false)
.property("key", "foo")
.property("file", xmlFilePath);
ToolboxFactory factory = config.createFactory();
template = Velocity.getTemplate(page.get("template-file"));
template.merge(context, write);
return write.toString();
但这不起作用。 如何使数据真正进入我的模板?我觉得我错过了很多步骤,但找不到我需要的信息!
【问题讨论】:
-
错误是什么?你的模板是什么样的?
标签: java velocity velocity-tools