This issue came up recently. I've been using ant for eons and know I could 'hack around' this issue, but thought to ask: does ant offer an elegant solution for this usecase?
Problem
When I use ant to copy xml files and "populate values" using the "filtering" attribute, how can I make it automatically escape ampersands (and other xml 'special characters')?
Context
Rather than have installers/implementers hand-edit all the various application-server specific configuration files, we have them edit a 'build.properties' files in our application's root directory. Ant copies a pre-configured 'source' version of the file to a 'target' directory whilst populating values from the properties files
1) Build.properties has this value:
JDBC_PASSWORD=smith&wesson
2) "Source" configuration file has this element:
<local-tx-datasource>
...
<password>@JDBC_PASSWORD@</password>
...
</local-tx-datasource>
3) Ant copies the xml files from the 'source' configuration directory and populates the 'JDBC_PASSWORD' (among others properties) with the 'filtering' attribute:
<copy todir="${appserver.home.dir}" filtering="yes">
<fileset dir="${appserver.conf.dir}">
<include name="**/*.xml"/>
</fileset>
</copy>
4) Because the property has an ampersand, the resulting 'target' xml file is invalid. (The '&' should be '&')
<local-tx-datasource>
...
<password>smith&wesson</password>
...
</local-tx-datasource>
Desired Result
Instead of 4, I would like this:
<local-tx-datasource>
...
<password>smith&wesson</password>
...
</local-tx-datasource>
Additional
I need to worry about the whole 'cast of characters', i.e. less-than, greater-than, etc., as well as the ampersand.
Thanks in advance