That's a nice elegant solution Arto... the first one that came to my
mind was to use Velocity (find it at apache.org). It's a decent generic
template language/engine. You can put any bean into a template's context
and do exactly what you are describing here.
If it's something you need to do "on-line" (e.g. to help generate
responses from a server) then you might want to consider using Velocity.
I would say Arto's idea (while I like it) might be more of
pain-in-the-butt to do on-line (though I suppose you could write a sax
entity resolver do to the replacements for you (though I've never used
the entity resolver interface so I'm no positive that's what it's for).
I do think, however, Velocity might be a better choice if only because
it provides more "out of the box" given that you want to do this from Java.
Arto Viitanen wrote:
>>"Michael" == Michael Ransburg <mi**@unfolded.com> writes:
Michael> Hello! I've got the following XML "template" (for example).
Michael> <personalData>
Michael> <address>
Michael> <name>$var1</name>
Michael> <zip>$var2</name>
Michael> </address>
Michael> <telephone type=$var3>$var4</telephone>
Michael> </personalData>
Michael> Is there an efficient way to replace the $var* variables by values
Michael> using Java? If not, what is an efficient way to work with such
Michael> templates?
You might like to try entities. So, instead of $var, you have &var;, which
you program could fill.