如何在nant中搜索xml文件中的特定单词?

时间:2013-07-03 13:23:24

标签: nant

我有一个XML文件,我想从我的NAnt脚本中搜索Error字。如果此error字存在,则会回显error exist

到目前为止,我没有找到任何合适的方法。有没有人有任何想法?

1 个答案:

答案 0 :(得分:1)

可能会因为${ ... }内部的混淆而感到困惑。希望这会有所帮助。

<?xml version="1.0"?>
<project name="Find a String" default="build" basedir=".">
<target name="build" description="various forms of string">
    <echo message="hardcoded strings" />
    <property name="stringFound" value="${string::contains('a string is a tiresome thing to search', 'tire')}" />
    <echo message="  stringFound=${stringFound}" />     
    <echo message="property strings" />
    <property name="stringToSearch" value="a property string is also a tiresome thing to search" />
    <property name="findThis" value="tires" />
    <property name="stringFound" value="${string::contains(stringToSearch, findThis)}"/>
    <echo message="  stringFound=${stringFound}" />
</target>
</project>

这给出了

 [echo] hardcoded strings
 [echo]   stringFound=True
 [echo] property strings
 [echo]   stringFound=True