Nant xmlpoke whole blocks

It took me awhile today to use the nant/xmlpoke/xpath to update our copyright message in our application so I’ll document it here.

The xmlpoke documentation explains whole to replace parameters but not children nodes. The simple answer is just define the parent in the xpath.

Thus to update/repalce the copyright string to have the correct current year, in a  resource file (strings.resx) which looks like:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <!-- other stuff -->
  <data name="About_Copyright" xml:space="preserve">
    <value>Copyright © 2008-2009 Company Name.</value>
  </data>
  <!-- more stuff -->
</root>

You would want use this xmlpoke/xpath

<xmlpoke
file="${sourceDir}\Resources\Strings.resx"
xpath="/root/data[@name = 'About_Copyright']/value"
value="Copyright © 2008-${datetime::get-year(datetime::now())} Company Name." />

Simple really (the xpath), but until I got it, it wasn’t.

This entry was posted in Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>