Ant xmlproperty任务。如果有多个标签具有相同的名称,会发生什么情况?
我正在尝试跟踪一个大型ant构建文件,在本例中,我很难理解xmlproperty的功能。 考虑这个XML文件,例如.x../p>Ant xmlproperty任务。如果有多个标签具有相同的名称,会发生什么情况?,xml,ant,Xml,Ant,我正在尝试跟踪一个大型ant构建文件,在本例中,我很难理解xmlproperty的功能。 考虑这个XML文件,例如.x../p> <main> <tagList> <tag> <file>file1</file> <machine>machine1</machine> </tag> <tag> <file>file
<main>
<tagList>
<tag>
<file>file1</file>
<machine>machine1</machine>
</tag>
<tag>
<file>file2</file>
<machine>machine2</machine>
</tag>
</tagList>
</main>
但是由于有两个
s,在本例中${PREFIX.main.tagList.tag.file}
的值是多少?如果是某种类型的列表,如何遍历这两个
值
我使用的是ant 1.6.2。当多个元素具有相同的名称时,
使用逗号分隔的值创建一个属性:
<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>
处理逗号分隔值时,考虑使用第三方ANTIFIB库:
<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>
很好的解释,谢谢。为了向阅读本文的其他人澄清,标记似乎默认在逗号分隔符上循环,这与相同的xmlproperty默认delimeter很好地配合使用。假设每个
都有一个唯一的属性值。是否有一种方法可以使用该属性值而不是使用Ant Contrib来访问属性的值?
<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>
run:
[echo] file1,file2
<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>
run:
[echo] file1
[echo] file2