xml - Ant xmlproperty task. What happens when there is more than one tag with the same name? -
i trying follow large ant buildfile have been given, , having trouble understanding functionality of xmlproperty in case. consider xml file, example.xml.
<main> <taglist> <tag> <file>file1</file> <machine>machine1</machine> </tag> <tag> <file>file2</file> <machine>machine2</machine> </tag> </taglist> </main> in buildfile, there task can simplified following example:
<xmlproperty file="example.xml" prefix="prefix" /> as understand it, if there 1 <tag> element, contents of <file> ${prefix.main.taglist.tag.file} because equivalent writing this:
<property name="prefix.main.taglist.tag.file" value="file1"/> but there 2 <tag>s, value of ${prefix.main.taglist.tag.file} in case? if sort of list, how iterate through both <file> values?
i using ant 1.6.2.
when multiple elements have same name, <xmlproperty> creates property comma-separated values:
<project name="ant-xmlproperty-with-multiple-matching-elements" default="run" basedir="."> <target name="run"> <xmlproperty file="example.xml" prefix="prefix" /> <echo>${prefix.main.taglist.tag.file}</echo> </target> </project> the result:
run: [echo] file1,file2 to process comma-separated values, consider using the <for> task third-party ant-contrib library:
<project name="ant-xmlproperty-with-multiple-matching-elements" default="run" basedir="." xmlns:ac="antlib:net.sf.antcontrib" > <taskdef resource="net/sf/antcontrib/antlib.xml" /> <target name="run"> <xmlproperty file="example.xml" prefix="prefix" /> <ac:for list="${prefix.main.taglist.tag.file}" param="file"> <sequential> <echo>@{file}</echo> </sequential> </ac:for> </target> </project> the result:
run: [echo] file1 [echo] file2
Comments
Post a Comment