ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jakob" <ja...@jfix.com>
Subject RE: xmltask problem
Date Thu, 22 Apr 2004 06:49:18 GMT
Keith,

> Ant properties are read-only; you cannot modify them
once set.
> So your first <property> tag is the problem.  This
should work.
>
> <project basedir="." default="test-existence"
> name="xmltask-test">
>  <taskdef name="xmltask"
> classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
>
>  <target name="test-existence">
>   <xmltask source="data/pub.xml">
>    <copy path="/publications/publication[@id='p1']/@id"
property="pid"/>
>   </xmltask>
>   <property name="pid" value="NOTGOOD"/><!-- not
overwritten if the XMLTask set it -->
> <echo>${pid}</echo>
>  </target>
> </project>

Thanks for your suggestion.

I found that it is not possible to copy the attribute's
value into the property (I tried both the "path" and
"attrValue" attributes for <copy>).

E:\>ant -buildfile buildxmltask.xml test-existence

test-existence:
  [xmltask] Applying CopyAction(eid) to
//publication[@id='rules']/@id
  [xmltask] Can only copy text() nodes and attribute
values to properties
  [xmltask] Applied CopyAction(pid) - 1 match(es)
     [echo] NOTGOOD

BUILD SUCCESSFUL
Total time: 0 seconds


But as I am only interested if there's a section with that
ID, I count() the ID and put that value in the property
"pid", like this:

<target name="test-existence">
 <xmltask source="data/pub.xml">
  <copy path="count(//publication[@id='rules']/@id)"
   property="eid"/>
 </xmltask>
 <property name="eid" value="0"/>
 <echo>${eid}</echo>
</target>


> Hope this helps
> Keith

It did, thanks again!

cheers,
Jakob.




> -----Original Message-----
> From: Jakob Fix [mailto:jakob@jfix.com]
> Sent: 21 April 2004 15:31
> To: user@ant.apache.org
> Subject: xmltask problem
>
>
> Hi,
>
> I am using xmltask (v1.10) from
> http://www.oopsconsultancy.demon.co.uk/software/xmltask/index.html
> and Ant 1.6.
>
> xmltask allows to create and modify xml documents from
> inside an Ant task.  It is neither a core nor optional
> Ant task, but very useful nevertheless.
>
> My problem is the following:  I need to update a small
> XML document through an auto-generated build file.  The
> XML document in question looks like this:
>
> <publications>
>  <publication id="p1">...</publication>
>  <publication id="p2">...</publication>
> </publications>
>
> The build file is auto-generated, and it contains a
> property which holds the ID value of the publication.
>
> The build file should have some way to find out whether
> a <publication> section with this ID exists already in
> the XML file, and therefore it should execute xmltask's
> <replace> command.  Otherwise, it should execute the
> <insert> command.
>
> I thought initially that I could use the xmltask's
> <copy> command to verify whether the ID exists, and if
> yes copy it into a regular Ant <property>, and then have
> two targets deal with the modify/create actions, using
> "if='property'".  However it seems, that I cannot do it
> this way:
>
> <project basedir="." default="test-existence"
> name="xmltask-test">
>  <taskdef name="xmltask"
> classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
> <property name="pid" value="NOTGOOD"/>
>
>  <target name="test-existence">
>   <xmltask source="data/pub.xml">
>    <copy path="/publications/publication[@id='p1']/@id"
> property="pid"/>
>   </xmltask>
>   <echo>${pid}</echo>
>  </target>
> </project>
>
> [echo] should display "p1", but shows "NOTGOOD".
>
>
> Anybody understands what I'd like to do?  And better
> yet, has a way to do it?
>
> Cheers,
> Jakob.
>
>
> ---------------------------------------------------------------------
> 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


Jakob.
--



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


Mime
View raw message