I´ve a Xml file with the struct below. I want to read the nod by node and call a specific task with the values without commom separator.In Ant this is possible ?
<
thiagolsilva,
Using a combination of xmlproperty and javascript I was able to split a multi-element (same node) of a projects.xml file and use project node data fields in ant. All actions are performed in a single ant file, in a single execution.
The sample data projects.xml file from the example above:
Project 1
//someurl1
project1
Project 2
//someurl2
project2
Has to be transformed into following format of projects.xml file:
Project 1;//someurl1;project1
Project 2;//someurl2;project2
Here, the previous node elements were transformed into a single string with fields separated by ‘;’ character.
I have renamed the element “project” to “myProject” to avoid confusion, as I will be using ant “project” object in javascript.
Once we have flattened the repeatable xml node into a string, we can use the following ant script to iterate through the elements, read the flattened properties and use them as we wish.
Process Projects
The files in: - C:\temp\lib\ProcessProjects.xml - the build - C:\temp\lib\projects.xml - the data - C:\temp\lib\ant-contrib-1.0b3.jar - the lib jar
The output:
C:\temp>ant -f ProcessProjects.xml
Buildfile: C:\temp\ProcessProjects.xml
init:
ProcessProjects:
[echo] Process Projects
processLoopStep:
[echo] myProject name = Project 1 url = //someurl1 package = project1
processLoopStep:
[echo] myProject name = Project 2 url = //someurl2 package = project2
BUILD SUCCESSFUL
Total time: 0 seconds
Regards, Jurek