Rebhan, Gilbert schrieb:
>
> -----Original Message-----
> From: ca_iancu [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 10, 2008 2:11 AM
> To: [email protected]
> 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="//[EMAIL PROTECTED]'${old.source.device}']/." buffer="foobar" />
> <insert path="//[EMAIL PROTECTED]'some_device']/." buffer="foobar"
> position="after"/>
> <replace path="//[EMAIL PROTECTED]'${old.source.device}'][2]/@name"
> withText="${new.source.device}" />
sorry,should have been =
<xmltask source="File.xml" report="true" dest="File.xml">
<copy path="//[EMAIL PROTECTED]'${old.source.device}']/." buffer="foobar"/>
<insert path="//[EMAIL PROTECTED]'${old.source.device}']/." buffer="foobar"
position="after"/>
<replace path="//[EMAIL PROTECTED]'${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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]