【问题标题】:how i can traverse the xml path dynamically in antscript?如何在 antscript 中动态遍历 xml 路径?
【发布时间】:2013-01-24 09:36:44
【问题描述】:

谁能告诉我,如何在 antscript 中动态遍历 xml 路径?如果父标签是从命令行参数给出的。有了这个,我必须形成子标记路径..访问 xml 文件,以从形成的 xml 标记路径中提取值。

ant -DId=abc

给定文件是

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

输出 16 是否正确?

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

【问题讨论】:

    标签: ant xml-parsing


    【解决方案1】:

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

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

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

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

    另见以下类似问题:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-17
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 2013-09-01
      相关资源
      最近更新 更多