Reputation:
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
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...
xmlpeek
to load the nodes you want to append to into a variableuse 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}' />" />
<xmlpoke file="${configFile}" xpath="/configuration/appSettings" value="${newAppSettingsNodes}" />
Upvotes: 5
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