ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilbert Rebhan <...@schillbaer.de>
Subject Re: how to copy and edit a section of a text file
Date Thu, 16 Oct 2008 18:31:11 GMT
Rebhan, Gilbert schrieb:
> 
> -----Original Message-----
> From: ca_iancu [mailto:ca_iancu@hotmail.com]
> Sent: Friday, October 10, 2008 2:11 AM
> To: user@ant.apache.org
> Subject: Re: how to copy and edit a section of a text file
> 
> /*
> No, I mean copy the entire section as written down before: from <device name
> .... to </device>. I keep the old section, then I append the new one which
> is almost identical but not quite. If you look again at the code, you will
> see that the second xml file (the one I would like to get) is different than
> the first one. Here's another attempt, where device1 is duplicated and it
> becomes device2.They are independent entities now. Thank you.
> */
> 
> Sorry for the late reponse, had been off some days.
> Here a quick shot with xmltask =

P.S. :
here's the xmlstructure i tested with Ant 1.6.5 /jdk 1.5.0
and xmltask 1.15.1

File.xml before :

<devices>
  <device name="some_device">
  content
  </device>
<devices>


> <project name="test" default="main" basedir=".">
> <!-- // Taskdefs -->
> <!-- Import XMLTask -->
> <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" />
> <!-- Taskdefs // -->
> <!-- // Properties -->
>  <property name="old.source.device" value="some_device"/>
>  <property name="new.source.device" value="some_other_device"/>
> <!-- Properties // -->
> 
> <target name="depends">
>  <xmltask source="File.xml" report="true" dest="File.xml">
>   <copy path="//device[@name='${old.source.device}']/." buffer="foobar" />
>   <insert path="//device[@name='some_device']/." buffer="foobar" position="after"/>
>    <replace path="//device[@name='${old.source.device}'][2]/@name"
>   withText="${new.source.device}" />

sorry,should have been =
<xmltask source="File.xml" report="true" dest="File.xml">
 <copy path="//device[@name='${old.source.device}']/." buffer="foobar"/>
<insert path="//device[@name='${old.source.device}']/." buffer="foobar"
 position="after"/>
<replace path="//device[@name='${old.source.device}'][2]/@name"
 withText="${new.source.device}" />

>  </xmltask>
> </target>
> 
> <target name="main" depends="depends">
>  <xmltask>
>   <print buffer="foobar"/>
>  </xmltask>
> </target>
> </project>

File.xml afterwards :

<devices>
  <device name="some_device">
   content
  </device>
  <device name="some_other_device">
   content
  </device>
<devices>


you need xmltask, get it here =
http://www.oopsconsultancy.com/software/xmltask/#download


Regards, Gilbert

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


Mime
View raw message