速度工具 XmlTool
Velocity Tool XmlTool
我正在尝试使用 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();
但这不起作用。
如何使数据真正进入我的模板?感觉少了很多步骤,就是找不到我需要的资料!
好吧,我的同事更聪明,他应该首先做这件事。
XmlTool tool = new XmlTool();
tool = tool.read(dataFile.getAbsolutePath());
context.put("foo", tool);
我正在尝试使用 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();
但这不起作用。 如何使数据真正进入我的模板?感觉少了很多步骤,就是找不到我需要的资料!
好吧,我的同事更聪明,他应该首先做这件事。
XmlTool tool = new XmlTool();
tool = tool.read(dataFile.getAbsolutePath());
context.put("foo", tool);