如何到<的foreach>在< macrodef&GT ;? [英] How to <foreach> in a <macrodef>?

查看:122
本文介绍了如何到<的foreach>在< macrodef&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML就像如下:

I have a xml just like below:

<data>

    <foo>value1</foo>

    <foo>value2</foo>

    <foo>value3</foo>

  </data>

我要创建macrodef它实现以下功能:

I want to create macrodef which implements below function:

<?xml version="1.0"?>
<project name="OATS" default="execute" basedir=".">

  <xmlproperty file="data.xml" collapseAttributes="true"/>
  <target name="execute">
    <foreach list="${data.foo}" target="runScript" param="script"/>
  </target>
  <target name="runScript">
    <echo>Doing things with ${script}</echo>
  </target>
</project>

任何人知道如何?先谢谢了。

Anybody knows how to ? Thanks in advance.

推荐答案

xmltask 是在蚂蚁社区实现这一目的的最佳选择,而且你不必定义自己的macrodef。

xmltask is the best choice in the Ant community for this purpose, and you don't have to define your own macrodef.

因此​​,例如:

  <tools:xmltask source="data.xml" report="false" >
    <tools:call path="data/foo">
      <param name="value" path="text()"/>
      <actions>
          <echo>Doing things with @{value}</echo>
      </actions>
    </tools:call>
  </tools:xmltask>

我鼓励你阅读用户手册,为xmltask有很多的选择。它基本上支持XPath提取和重复你的XML的任何部分。它还支持除匿名code块现有目标调用(如示例)。

I encourage you to read the user manual, for xmltask has lots of options. It basically supports XPath to extract and iterate any portion of your xml. It also supports calls to existing targets in addition to anonymous code blocks (as in the example).

这只是很难被击败。

这篇关于如何到&lt;的foreach&GT;在&LT; macrodef&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆