ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Agnew <br...@oopsconsultancy.com>
Subject Re: AW: How to use replaceregexp in multi-line context?
Date Thu, 18 May 2006 17:01:16 GMT
If you're trying to replace stuff in XML but only for particular nodes 
(e.g. in the below you're scoping on an attribute value) then I'd suggest:

http://www.oopsconsultancy.com/software/xmltask/

and doing:
<replace path="/entry[@name='statistics.enabled']/value/text()" 
withText="true"/>

Brian

Oliver Ashoff wrote:
> Hello David!
>  
>
> Example: Consider the following lines of an input file:
>  
>       <entry name="statistics.enabled">
>         <value>true</value>
>       </entry>
>  
> Now, we want to replace the string "true" by "false". But this should be
> done
> only for the entry "statistics.enabled". So, I use a regular expression
> that 
> matches the above three line:
>  
>  <replaceregexp byline="false" flags="m">
>    <regexp
> pattern="(.*&lt;entry.*name=&#34;statistics.enabled&#34;.*&gt;.*&#10;.*&
> lt;value&gt;).*(&lt;/value&gt;.*&#10;.*&lt;/entry&gt;.*$)" />
>    <substitution expression="\1false\2" />
>    <fileset dir="${etc.dir}" includes="config.xml" />
>   </replaceregexp>
>  
> As you can see, I inserted 2 times the sequences  
>    &#10;
> so that the 'line breaks' are recognized. Without that it does not work.
> Additionally, I use further 'Numerical Character References'  for the
> characters '<' and '>'.

-- 
Brian Agnew                  http://www.oopsconsultancy.com
OOPS Consultancy Ltd         brian @ oopsconsultancy.com
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012



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


Mime
View raw message