Given the following xml:
<rootnode>
<childnode arg="a">Content A</childnode>
<childnode arg="b">Content A</childnode>
</rootnode>
Using XMLPoke with the following XPath:
rootnode/childnode[arg='b']
The result (if the replace string is empty) is:
<rootnode>
<childnode arg="a">Content A</childnode>
<childnode arg="b"></childnode>
</rootnode>
The contents of the childnode have been removed when we actually want the childnode itself removed. The desired result is:
<rootnode>
<childnode arg="a">Content A</childnode>
</rootnode>
The childnode must be selected based on the childnode argument.
I hold my hands up! This is a classic case of asking the wrong question.
The problem is that you can't use xmlpoke to remove a single node. Xmlpoke can only be used to edit the contents of a specific node or attribute. There isn't an elegant way to remove a child node as per the question using only the standard Nant targets. It can be done using some inelegant string manipulation using properties in Nant, but why would you want to?
The best way to do this is to write a simple Nant target. Here's one I prepared earlier:
Combine the above with a modification to the NAnt.exe.config file to load the custom target and the following script in the build file:
This will remove the childnode with an argument arg with value b from target.xml. Which is what I actually wanted in the first place!