I am using Ant to build my software. Ant creates an Xml file with the echoxml function and then provides the created xml file to another special program.
Now I would like to list the content of a directory in the echoxml tag.
How can this be done? My final xml file should look something like this, only providing a path to the directory:
<SomeXmlTag>
<cp>directory/firstFile.jar</cp>
cp>directory/secondFile.jar</cp>
<cp>directory/XYZFile.jar</cp>
</SomeXmlTag>
EchoXML is an ant tast which is already specified to take a nested xml string as its contents, outputting those contents directly to a file (or to the console). So according to the documentation, it doesn’t satisfy your needs.
However, it is pretty simple to modify a standard ant task to do this using the javax xml extensions and along with a the File api.
First, See http://ant.apache.org/manual/Tasks/echoxml.html, and confirm that EchoXML does not do what you need it to do.
Now, a simple solution is to implement your own xml writer task … to simply write your own class :
And then add this to your build :