velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duttaroy, Debasish" <debasish.dutta...@fmr.com>
Subject How to use EscapeTool
Date Tue, 29 Aug 2006 20:26:57 GMT
Hi
I am new to Velocity. Here is my requirement.

I want the velocity template to spit out a xml output. Basically, my .vm
file is a xml template. I am able to achieve this. Now I want the data
inside this xml document to be escaped.

What is the best way to do this.

My understanding is this should be done with the help of EscapeTool.
BTW, I use Spring MVC. This is what I do:

My hello.vm

## Velocity Hello World
<?xml version="1.0"?>
<headlines>
	<lineitem>
	
<headlinetext>${esc.xml($headline.headlineText)}</headlinetext>
	</lineitem>
</headlines>

Required output

<headlines>
	<lineitem>
		<headlinetext>Times &amp; Warner</headlinetext>
	</lineitem>
</headlines>


Actual Output

<headlines>
	<lineitem>
		<headlinetext>Times & Warner</headlinetext>
	</lineitem>
</headlines>


I put toolbox.xml inside WEB-INF

<?xml version="1.0"?>
<tool>
	<key>esc</key>
	<scope>application</scope>
	<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>


What else do I need to do. If anyone can provide a step by step method
to best way of doing escaping that will be great. I can achieve what I
want by some crude means, but I want the best practice not the hack.

Thanks in advance
Debasish

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message