ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Blaine Simpson <blaine.simp...@admc.com>
Subject Re: AW: Modify xml file
Date Wed, 21 Jan 2009 14:49:10 GMT
My favorite way is to use unicode escapes.  Not only does it work for
every character you will need (visible or not visible), but unicode
escapes work for all XML, properties, and even Java source files (using
different syntax, as explained below).  For Ant build files: "&#" +
2_DIGIT_DECIMAL_NUMBER + ";" Since the first 127 unicode mappings are
the same as ASCII, you can use any ascii chart to find the character you
need, like at
http://en.wikipedia.org/wiki/ASCII_chart#ASCII_control_characters and
http://en.wikipedia.org/wiki/ASCII_chart#ASCII_printable_characters . 
Examples

    \r = &#13;
    \n = &#10;
    < = &#61;
    \ = &#92;

You can also use Hex instead of decimal numbers by prefixing the number
with "x", like &#0d; for the \r.

For properties files and Java source files, you can use the same octal
codes but with this format:  "\u" + 4_DIGIT_HEX_NUMBER, like  \u000d for \r.

Alec Fernandez wrote:
> You should exercise caution when using replace to substitute tokens in xml files and
property files because some chars &<>'" need to be escaped in xml files.
>
> You need to be sure that the string that you are inserting into the xml will never have
such characters, or you must escape yourself.
>
> Similarly there are chars (\ and non-Latin 1 chars) that need escaping in .properties
files.  
>
> If someone knows of an elegant solution to inserting such strings into files using ant,
I would be grateful for the input.
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message