2016-08-25 41 views
1

我試圖用ANT replaceregexp任務將xml元素的值從「true」更改爲「false」,但是在新行中匹配有困難。 XML節點的有問題的相關部分:ant replaceregexp xml換行

<validationRules> 
    <fullName>CAReversaApprovallLockdown</fullName> 
    <active>true</active> 

在我的文本編輯器(昇華),我可以使用下面的正則表達式查找/替換,但我無法弄清楚如何複製這種ANT replaceregexp:

/fullname>\n  <active>true 

我找不出正確的語法來匹配換行符和後續間距的組合。換行符之後的間距總是相同的,如果這樣做更容易。

看着https://ant.apache.org/manual/Tasks/replaceregexp.html我已經嘗試過各種組合的^和$ m標誌,\ s +的空間等,但只是不能擊中正確的組合....任何想法?

我目前的進展低於但沒有運氣不幸......

<target name="deactivate_val_rules"> 
    <echo message="deactivating validation rules..." /> 
    <replaceregexp match="/fullname&gt;\r\n\s+&lt;active&gt;true" flags="gim" byline="false"> 
     <substitution expression="/fullname&gt;\r\n  &lt;active&gt;false"/> 
     <fileset dir="src\objects" includes="Claim_Approvals__c.object"/> 
    </replaceregexp> 
</target> 

回答

0

得到它 - 下面給出正確的結果:

<target name="deactivate_val_rules"> 
    <echo message="deactivating workflows..." /> 
    <replaceregexp match="/fullname&gt;\r\n\s+&lt;active&gt;true" flags="gis" byline="false"> 
     <substitution expression="/fullname&gt;${line.separator}  &lt;active&gt;false"/> 
     <fileset dir="src\objects" includes="Claim_Approvals__c.object"/> 
    </replaceregexp> 
</target> 

經由差速器觀察的輸出是:

- <fullName>the_name</fullName> 
    - <active>true</active> 
    + <fullName>the_name</fullname> 
    + <active>false</active> 
0

要使用replaceregexp您需要定義的值被改變爲參考。

例如:

<validationRules> 
    <fullName>CAReversaApprovallLockdown</fullName> 
    <active>true</active> 

螞蟻:

<target name = "deactivate_val_rules"> 
    <echo message="deactivating validation rules..." /> 
    <replaceregexp file="${FILE_LOACTION}/FILE_NAME.FILE_EXT" match="true" replace="false" /> 
</target> 
+0

所以你需要掃描你所有的嵌套文件目錄尋找元素並取代它的值? –

+0

我不能做一個簡單的真假替換,因爲有其他節點有一個元素 - 文件中最小的唯一值是元素在一個新行上 – nom