Ant: Iterating through an XML file's nodes

Go To


I have the following XML structure:


I need to retrieve a file from each server, from a folder I know, attach it to an email and then send it.

What would be the approach for this?


2012-04-03 20:55
by bruneti12


Use the xmlproperty task to load an XML file into properties.

Then use the for task from ant-contrib to act upon each of the matched properties.

Something like:

<target name="funtimes">
    <xmlproperty file="the.xml" delimiter=","/>
    <for list="${servers.hostname}" param="hostname">
            <echo>Doing things with @{hostname}</echo>

Fetching files depends upon how you are planning to access them. The scp task might help.

For sending email you can use the mail task.

2012-04-03 23:42
by Synesso
What I have in mind for fetching the files is copying them one by one to a local shared folder using the for task which you explained me previously. And then, in the mail task, attaching them to the email putting them all together in a FileSet. I'm new at Ant and I'm doing some research to see if this is possible :) - bruneti12 2012-04-04 12:45