prabug
prabug

Reputation:

How to append XML nodes using existing Nant or Nant Contrib tasks?

During a build process using Nant, how to update an xml file, for adding new nodes. I wish to do this by using existing Nant/NantContrib tasks

Upvotes: 3

Views: 2547

Answers (2)

craigb
craigb

Reputation: 16907

here's an article explaining in some detail: http://weblogs.asp.net/bsimser/archive/2008/01/03/appending-nodes-in-xml-files-with-xmlpeek-and-xmlpoke-using-nant.aspx

Basically...

  1. use xmlpeek to load the nodes you want to append to into a variable
  2. append your new node (as a string) to the variable from step 1
  3. use xmlpoke to replace the nodes selected in step 1

    <xmlpeek file="${configFile}" xpath="/configuration/appSettings" property="appSettingsNodes" />

    <property name="newAppSettingsNodes" value="${appSettingsNodes}<add key='my.config.key' value='${someNewValue}' /&gt;" />

    <xmlpoke file="${configFile}" xpath="/configuration/appSettings" value="${newAppSettingsNodes}" />

Upvotes: 5

The Chairman
The Chairman

Reputation: 7187

You might use <xmlpoke> for that.

But I would suggest, you do yourself a favor and use <script> to write xml file modification logic in the language of your choice.

Upvotes: 2

Related Questions