我有以下 XML 结构:
<servers>
<hostname>ABC01</hostname>
<hostname>ABC02</hostname>
</servers>
我需要从每个服务器、我知道的文件夹中检索文件,将其附加到电子邮件中,然后发送。
解决这个问题的方法是什么?
谢谢。
最佳答案
使用xmlproperty
task将 XML 文件加载到属性中。
然后使用for
task来自ant-contrib对每个匹配的属性进行操作。
类似于:
<target name="funtimes">
<xmlproperty file="the.xml" delimiter=","/>
<for list="${servers.hostname}" param="hostname">
<sequential>
<echo>Doing things with @{hostname}</echo>
</sequential>
</for>
</target>
获取文件取决于您计划如何访问它们。 scp
task可能有帮助。
要发送电子邮件,您可以使用 mail
task .
关于Ant:遍历 XML 文件的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10001247/