07 November 2006

Problem with NAnt's xmlpoke task

There's an issue when trying to replace some part of an xml file that is under a default namespace using NAnt’s xmlpoke task. It happened to me the other day when trying to replace the version attribute in the following wix file:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi">
<Product Name="MyProduct" Id="847A8D24-0F98-4b9f-AEA0-070ABD49F86C" Language="1033" Codepage="1252" Version="1.0.0" Manufacturer="MyCompany">
......
</Product>
</Wix>

Because of the namespace definition in the Wix element, calling xmlpoke simple as
<xmlpoke file="${wix.file}" xpath="/Wix/Product/@Version" value="${build.new.version}"/>
does not work.

What it does work is the following use of the task:

<xmlpoke file="${wix.file}" xpath="/wx:Wix/wx:Product/@Version" value="${build.version}">
<namespaces>
<namespace prefix="wx" uri="http://schemas.microsoft.com/wix/2003/01/wi" />
</namespaces>
</xmlpoke>

9 comments:

Anonymous said...

Thank you Soledad, this was very helpful! :)
I was trying to do the same thing today and wondering why it didn't work...

Alan Lok said...

Thanks, you fixed my issue! I <3 the Internet!

Anonymous said...

when using xmlpoke it seems to add in a byte order mark to the .wxs file. Visual studio starts complaining about that and would not compile unless those are removed.

Is there anyway around this? Anyway to either force Nant not to put in the byte order marks or VS to ignore them?

Anonymous said...

Thanks for the post. I was having the same problem.

Unknown said...

Soledad, to the rescue! Thanks!

Rick
Portland, OR, USA

Unknown said...

Brilliant, thanks. Stuck on that problem for hours.

Adrian Grigore said...

Thanks so much for this post, you saved me a lot of banging my head against the nearest wall... :-)

MightyMuke said...

Thanks. You saved me some hours of frustration too.

VC said...

Hi Soledad,
if you don't mind sharing your thoughts on this:

I have properties.xml file with builds-info-xml defined similar like yours. I referred properties.xml into my default.build file and tried XMLPeek and XMLPoke to increment the versions and it didn't work at all. Nant kept complaining "[xmlpoke] No matching nodes were found with XPath expression..."

Even though, I referred same namespace, at the top of each file, in both the default.build and properties.xml file and I tried this suggestion too and didn't see any change.

Could you please throw some light on when to use namespaces and when it is not needed for these 2 tags?

Thanks

VC Sekhar Parepalli