Ant macrodef:有没有办法获取元素参数的内容?
我正在尝试调试Ant中的宏定义。我似乎找不到一种方法来显示作为元素发送的参数的内容Ant macrodef:有没有办法获取元素参数的内容?,ant,element,macrodef,Ant,Element,Macrodef,我正在尝试调试Ant中的宏定义。我似乎找不到一种方法来显示作为元素发送的参数的内容 <project name='debug.macrodef'> <macrodef name='def.to.debug'> <attribute name='attr' /> <element name='elem' /> <sequential> <echo>Sure, the attribute
<project name='debug.macrodef'>
<macrodef name='def.to.debug'>
<attribute name='attr' />
<element name='elem' />
<sequential>
<echo>Sure, the attribute is easy to debug: @{attr}</echo>
<echo>The element works only in restricted cases: <elem /> </echo>
<!-- This works only if <elem /> doesn't contain anything but a
textnode, if there were any elements in there echo would
complain it doesn't understand them. -->
</sequential>
</macrodef>
<target name='works'>
<def.to.debug attr='contents of attribute'>
<elem>contents of elem</elem>
</def.to.debug>
</target>
<target name='does.not.work'>
<def.to.debug attr='contents of attribute'>
<elem><sub.elem>contents of sub.elem</sub.elem></elem>
</def.to.debug>
</target>
</project>
因此,我想我需要一种方法将
的内容以某种方式放入属性中(某些扩展的macrodef实现可能会有这种方法),或者我需要一种
可以打印出放入其中的任何XML树。有人知道这两种方法的实现吗?当然,任何第三种非预期的获取数据的方法都是受欢迎的。任务如何
在您的示例中,生成文件替换了行
<echo>The element works only in restricted cases: <elem /> </echo>
给予
$ant不起作用
...
不工作:
[echo]当然,属性很容易调试:属性的内容
[echo]子元素的内容
元素正是我想要的,谢谢!作为奖励,“”甚至可以在不进行额外处理的情况下添加XML头(在ant 1.8.4上测试)。
<echo>The element works only in restricted cases: <elem /> </echo>
<echoxml><elem /></echoxml>
$ ant does.not.work
...
does.not.work:
[echo] Sure, the attribute is easy to debug: contents of attribute
<?xml version="1.0" encoding="UTF-8"?>
<sub.elem>contents of sub.elem</sub.elem>
<sequential>
<echo>Sure, the attribute is easy to debug: @{attr}</echo>
<echoxml file="macro_elem.xml"><elem /></echoxml>
<loadfile property="elem" srcFile="macro_elem.xml">
<filterchain>
<LineContainsRegexp negate="yes">
<regexp pattern=".xml version=.1.0. encoding=.UTF-8..." />
</LineContainsRegexp>
</filterchain>
</loadfile>
<echo message="${elem}" />
</sequential>
$ ant does.not.work
...
does.not.work:
[echo] Sure, the attribute is easy to debug: contents of attribute
[echo] <sub.elem>contents of sub.elem</sub.elem>