Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 844949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:22:04+00:00 2026-05-15T06:22:04+00:00

I am generating XML using Apache Velocity. What is the best (most straight-forward) way

  • 0

I am generating XML using Apache Velocity. What is the best (most straight-forward) way to XML-escape the output?

(I saw there is an escape tool, but could not figure out it’s dev state. I also think that XML escaping is something that is very likely supported by Velocity directly.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:22:05+00:00Added an answer on May 15, 2026 at 6:22 am

    Take a look at event handlers.

    eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeXmlReference
    

    Escape tool is a production ready as well if you need to escape only selective references (final version of tools was released just recently but it was in beta stage before that for 2 years if not longer)

    $esc.xml($var)
    

    How to init velocity tools.

    Include velocity-tools.xml into your project and enable required tools:

    <tools> 
        <data type="number" key="TOOLS_VERSION" value="2.0"/>
        <data type="boolean" key="GENERIC_TOOLS_AVAILABLE" value="true"/>
        <toolbox scope="application">
            <tool class="org.apache.velocity.tools.generic.AlternatorTool"/>
            <tool class="org.apache.velocity.tools.generic.DisplayTool"/>
            <tool class="org.apache.velocity.tools.generic.MathTool"/>
            <tool class="org.apache.velocity.tools.generic.NumberTool"/>
            <tool class="org.apache.velocity.tools.generic.ComparisonDateTool"/>
            <tool class="org.apache.velocity.tools.generic.ClassTool"/>
            <tool class="org.apache.velocity.tools.generic.ConversionTool"/>
            <tool class="org.apache.velocity.tools.generic.EscapeTool"/>
            <tool class="org.apache.velocity.tools.generic.FieldTool"/>
            <tool class="org.apache.velocity.tools.generic.ListTool"/>
            <tool class="org.apache.velocity.tools.generic.ResourceTool"/>
            <tool class="org.apache.velocity.tools.generic.SortTool"/>
        </toolbox>
        <toolbox scope="request">
            <tool class="org.apache.velocity.tools.generic.LoopTool"/>
            <tool class="org.apache.velocity.tools.generic.ContextTool"/>
            <tool class="org.apache.velocity.tools.generic.LinkTool"/>
            <tool class="org.apache.velocity.tools.generic.RenderTool"/>
        </toolbox>
    </tools>
    

    Then velocity context creation procedure would look like:

    ToolManager velocityToolManager = new ToolManager();
    velocityToolManager.configure("velocity-tools.xml");
    VelocityContext context = new VelocityContext(velocityToolManager.createContext());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having no luck in generating XML with fixed element values using JAXB 2.1 RI.
I am using XML Data Mapping and having a problem with generating complex types
Hi I have following which is not generating class file for complextypes using bindigs.xml
I am trying to update an xml schema by using the xsd tool. The
I need to find a way to get all Apache running request at a
I need to transform XML using xslt. Logic: Split the parent if the parent
I have a program that is generating Xml Files from data out of a
Here's the situation: I have a client who's issued me an XML schema, and
I'm dynamically calling web services in my program using the WSProxy class here ,
I have a legacy class, with a lot of public double fields. All double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.