Xmlpoke in Nant - how to update all instances of a found string

Hi I am using Xpath in my Nant script assembly to modify some configuration variables between development and other environments.

I took the syntax from this example:

An example is as follows:

<xmlpoke
    file="config01/app.config"
    xpath="/configuration/appSettings/add[@key='AppName']/@value"
    value="TradeMonster">
</xmlpoke>

What I would like is to look for connection strings and find all instances of "localhost \ SqlExpress" and just change them to "localhost"

Is it possible?

+5
source share
2 answers

Playing with a quick dirty script here ....

, connectionstring, xmlpeek xmlpoke. #, script :

 <script language="C#" prefix="custom" >
      <code>
        <![CDATA[
          [Function("fix")]
          public static string Fix(string input) {
              return Regex.Replace(input, @"localhost\\\w+", "localhost");
          }
        ]]>
      </code>
  </script>

<!-- Get the existing connection string -->
<xmlpeek
    file="config01/app.config"
    xpath="/configuration/connectionStrings/add[@contains(@connectionString,'localhost\')]/@connectionString"
    property="connectionstring">
</xmlpeek>

<!-- Write back the modified connection string -->
<xmlpoke
    file="config01/app.config"
    xpath="/configuration/connectionStrings/add[@contains(@connectionString,'localhost\')]/@connectionString"
    value="${custom::fix(connectionstring)}">
</xmlpoke>
+4

XPath , .

XSLT XML.

, XML- , .

0

All Articles