• Post Reply Bookmark Topic Watch Topic
  • New Topic

is Velocity best choice for outputting XML with a template XML file?  RSS feed

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.roseindia.net/apachevelocity/xml.shtml

That example above shows how to use Velocity to take in a template XML file and merge your data into it to output a populated XML file. If I want to output an XML file with dynamic data by using some kind of template tags in an XML file, is Velocity the best choice out there?

Basically, if I have a template file with stuff like



in it, do you recommend Velocity for populating it?

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the format of the files is fixed in this way, sure, why not. Just make sure that Velocity (and/or your code) handles setting the encoding correctly. As an alternative, you could check out FreeMarker, which is the other widely used templating tool.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip! I'm actually planning to do this on Google App Engine, and it looks like it wasn't working for someone on GAE in December due to a dependency on javax.swing:

http://solveme.wordpress.com/2009/12/25/freemarker-sucks-it-has-dependency-on-javax-swing/

I'll try Velocity for now.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used a variety of templating engines for outputting XML; they work fine.

If your needs are simple it can often be just as easy to throw stuff into the classes being output, or into a wrapper/facade.

XStream is pretty easy to use, but don't know about GAE compatibility.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!