2

I am trying to use XmlTool to parse an XML file to be able to use the data in a Velocity template.

However, the documentation on it is all pretty poor and doesn't really give the information I need.

The documentation is at: https://velocity.apache.org/tools/devel/apidocs/org/apache/velocity/tools/generic/XmlTool.html

And I have tried:

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();

But this is not working. How do I make the data actually make it's way to my template? I feel like I am missing so many steps, but just can't find the information I need!

marcusds
  • 784
  • 1
  • 7
  • 26

1 Answers1

2

Well my co-worker who is the smarter one who should have been doing this in the first place figured it out.

XmlTool tool = new XmlTool();
tool = tool.read(dataFile.getAbsolutePath());
context.put("foo", tool);
marcusds
  • 784
  • 1
  • 7
  • 26