Of course, the template must have all tags balanced and such, to start with. Consider this simple template:
As long as the string representation of the value variable in the Velocity context is something innocuous as “foobar”, everything is fine. But if it were “foo & bar” instead, you’d get this output:
which is most definitely not valid XML! The correct output should have been:
So there must be a solution. Of course, there is a really obvious and bad solution, which is going over all the values passed into the Velocity context and escaping all XML special characters like ‘&’, ‘<’ and so on. This might work for a simple case like the one above, but would break down horribly when your data model is a complex collection of arbitrary objects.
Please, don’t tell me that Velocity sucks as much as I think it does!
No comments:
Post a Comment