0

Could anyone tell me, how can I traverse the xml path dynamically in antscript? If the parent tag is given from command line arguement. with this , i have to form child tag path ..access the xml file , to pull the value form the formed xml tag path.

ant -DId=abc

Given file is

<abc>
 <Age>16</Age>
</abc>

Is this correct to give output 16?

<echo>${${Id}.Age}</echo>
4

1 回答 1

0

ANT 不是脚本语言,不幸的是,不支持属性中的属性:-(

我建议的解决方案是嵌入式groovy 脚本

<target name="parse">
    <groovy>
        def data = new XmlSlurper().parse(new File("data.xml"))

        println data.Age
    </groovy>
</target>

方便地(在您的情况下)groovy xml 解析器忽略根标记的名称,这意味着您不必将其作为参数传递。

另请参阅以下类似问题:

于 2013-01-24T20:31:48.763 回答