> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Brian Agnew
> Sent: Friday, March 28, 2008 5:33 AM
> To: Karr, David
> Cc: xmltask-users@lists.sourceforge.net
> Subject: Re: [Xmltask-users] Add text to web-app/description 
> if it's present
> 
> Hi David -
> 
> 1) I think the problem is that Ant properties are 
> derived/expanded per task. That is, populating a property 
> within XMLTask makes it available for use in another task, 
> but not the current one. I'm not able to investigate further 
> at the moment, but copying into your property in one XMLTask 
> invocation then writing using another one appears to work. e.g.
> 
>       <xmltask source="web.xml">
>         <copy path="..." property="..."/>
>       <xmltask>
>       <xmltask source="web.xml" dest="web-out.xml">
>          <paste.../>
> 
> etc. appears to work for the below.

This had an even worse symptom.  Previously, the "if" and "unless"
worked correctly, in that if something was in the property, the "if"
succeeded, and if not, the "unless" succeeded.  However, the resulting
inserted data seemed to indicate the property was not set.  However,
after making this prescribed change, the "if" check fails, even when the
property should be set.

> nb. your XPaths may be simplified by using
> 
> /:web-app/:description
> 
> rather than the verbose but correct 'local-name()' syntax 
> (caveat: not tried - just by inspection).

This works.

> On Thu, March 27, 2008 23:56, Karr, David wrote:
> > It's been a while since I've xmltasked.  I'm having some trouble 
> > getting done what I need.
> >
> > I have some text in a couple properties (I'm hardcoding the 
> values for
> > now) that I want to put into the "/web-app/description" 
> element of a 
> > web.xml file.  If the element is already present, I want to add the 
> > new text after " - ".  If the element wasn't present, then 
> create the 
> > element with the new text.
> >
> > I have two current problems:
> >
> > If the "description" element was present already, it's supposed to 
> > insert a value referencing the property containing the 
> existing value.
> > Instead of the value of the property, it just inserts 
> > "${existingDescription}".  I tried printing out the property value 
> > after the xmltask tag, and it appears to be fine.
> >
> > If the "description" element was NOT present, I insert the new 
> > "description" element (using that weird trick just talked about for 
> > turning off insertion of empty "xmlns" attributes), but it 
> inserts it 
> > as the last child of "web-app", not the first.  I don't see 
> a way to 
> > do this cleanly.
> >
> > I also wish there was a cleaner way to "trim" the resulting output 
> > (see what I had to do in the first "replace").
> >
> > Here's my current code:
> > ---------------------
> > <target name="install-label-info">
> >         <taskdef name="xmltask"
> > classname="com.oopsconsultancy.xmltask.ant.XmlTask"
> >                  classpath="${file.reference.xmltask.jar}"/>
> >         <property name="label" value="abc"/>
> >         <property name="labelDesc" value="def"/>
> >         <xmltask source="${build.web.dir}/WEB-INF/web.xml"
> > dest="${build.web.dir}/WEB-INF/web.xml" report="true">
> >                     <copy
> > 
> path="/*[local-name()='web-app']/*[local-name()='description']/text()"
> > property="existingDescription"/>
> >             <replace if="existingDescription"
> > 
> path="/*[local-name()='web-app']/*[local-name()='description']/text()"
> >                      expandProperties="true"
> >                 ><![CDATA[${existingDescription} - ${label}:
> > ${labelDesc}]]></replace>
> >             <paste unless="existingDescription"
> > path="/*[local-name()='web-app']/.">
> >                 <![CDATA[<description
> > xmlns="http://java.sun.com/xml/ns/j2ee";>${label}:
> > ${labelDesc}</description>]]>
> >             </paste>
> >                     <copy
> > 
> path="/*[local-name()='web-app']/*[local-name()='description']/text()"
> > property="newDescription"/>
> >         </xmltask>
> >         <echo 
> message="existingDescription[${existingDescription}]"/>
> >         <echo message="newDescription[${newDescription}]"/>
> >     </target>
> > ---------------------
> >
> >
> >
> >
> > 
> ----------------------------------------------------------------------
> > --- Check out the new SourceForge.net Marketplace.
> > It's the best place to buy or sell services for just about anything 
> > Open Source.
> > 
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
> > tplace _______________________________________________
> > Xmltask-users mailing list
> > Xmltask-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/xmltask-users
> >
> 
> 
> -- 
> Brian Agnew                  http://www.oopsconsultancy.com
> OOPS Consultancy Ltd
> Tel: +44 (0)7720 397526
> Fax: +44 (0)20 8682 0012
> 
> 
> --------------------------------------------------------------
> -----------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for just about 
> anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n
et/marketplace
> _______________________________________________
> Xmltask-users mailing list
> Xmltask-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/xmltask-users
> 

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Xmltask-users mailing list
Xmltask-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xmltask-users

Reply via email to