Tôi đang cố gỡ lỗi macrodef trong Ant. Tôi dường như không thể tìm cách hiển thị nội dung của tham số được gửi dưới dạng phần tử.Macrodef kiến: Có cách nào để lấy nội dung của tham số phần tử không?
<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>
Ví dụ chạy:
$ ant works
...
works:
[echo] Sure, the attribute is easy to debug: contents of attribute
[echo] The element works only in restricted cases: contents of elem
...
$ ant does.not.work
...
does.not.work:
[echo] Sure, the attribute is easy to debug: contents of attribute
BUILD FAILED
.../build.xml:21: The following error occurred while executing this line:
.../build.xml:7: echo doesn't support the nested "sub.elem" element.
...
Vì vậy, tôi đoán tôi cần hoặc là một cách để có được nội dung của <elem />
thành một tài sản nào đó (một số thực hiện macrodef mở rộng có thể có đó), hoặc tôi cần một loại <element-echo><elem /></element-echo>
có thể in ra bất kỳ cây XML nào bạn đặt bên trong. Có ai biết về việc thực hiện một trong những điều này? Bất kỳ cách thức thứ ba, bất ngờ nhận dữ liệu nào cũng được hoan nghênh.
Lệnh ' ' yếu tố chính xác là những gì tôi đang tìm kiếm, cảm ơn bạn! –
clacke
Là phần thưởng, ' ' hoạt động ngay cả khi không có xử lý bổ sung để thêm tiêu đề XML (được thử nghiệm trên kiến 1.8.4). –