ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: replace section of file, loadFile, replaceregex, filterchain
Date Thu, 20 Jul 2006 10:14:57 GMT
Hi,

when working (replace ...) with xml files i would go
with the xml task =

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

then you can select the specific nodes via xpath

 
Regards, Gilbert

-----Original Message-----
From: Gaz Smith [mailto:topqualitybanter@yahoo.co.uk] 
Sent: Thursday, July 20, 2006 10:43 AM
To: user@ant.apache.org
Subject: replace section of file, loadFile, replaceregex, filterchain

Hey, wonder if you guys can help me? I'm trying to use
ant to copy a portion of one text file
in to another text file. I have specific markers that
I can use for this.


The source file has the format shown below,

// ----- src file start

a few

lines of text

<service name="ServiceName" ... >

   One or more
   lines of stuff
   
</service>

more stuff I don't want.

// ----- src file end


In the destination file I want to replace the existing
entry between (and including the service tags)
with the one extracted from the above file. 

// ----- dest file start

a few lines of
some text 

<service name="ServiceName" .... >

   the old copy of the
   service definition
   that i want to replace
   
</service>

more stuff to be ignored

// ----- dest file end



Now I believe I can achieve the above using something
like the following,

<loadfile property="wsdd" srcfile="srcFile.txt">
    <filterchain>
        <tokenfilter>
            <filetokenizer/>
            <replaceregex pattern="^.*&#60;service
name&#61;&#34;ServerName&#34;" replace="" flags="s"/>
            <replaceregex pattern="service&#62;.*$"
replace="" flags="s"/>
        </tokenfilter>
     </filterchain>
</loadfile>

<replace file="destFile.txt" token="@SPECIAL_TOKEN@"
value="${wsdd}"/>


1. The regex isn't up to scratch. What I really want
to do it extract the bit between the tags and 
ignore the rest. Any suggestions?

2. The replace file will only work if the token is in
the file (obviously). The problem here is that
I can run the task over and over again replacing the
old value in destFile. What I really want to do
on each replace is replace the portion between
<service name="ServiceName"..> and the next </service>
tag.

Many thanks for your time,
gaz.


		
___________________________________________________________ 
The all-new Yahoo! Mail goes wherever you go - free your email address
from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html

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


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


Mime
View raw message