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

During the build process using Nant, how to update the xml file to add new nodes. I want to do this using existing Nant / NantContrib tasks

+3
source share
2 answers

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

Mostly...

  • use xmlpeekto load the nodes you want to add to the variable
  • add a new node (as a string) to the variable from step 1
  • use xmlpoketo 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}" / >

+4
+2

Source: https://habr.com/ru/post/1716656/


All Articles