nant/nant — Issue #14: Enable xmlpoke to replace nodes
Author: fhaag
Created: 2011-12-24 10:26:35+00:00
State: open

The xmlpoke task can only replace the contents of a particular node. Imagine an Xml document like this:

```xml

```

With xmlpoke, it is not possible (as far as I can see) to replace with .

Proposed solution: Add a new "replaceContents" parameter to xmlpoke that defaults to "true". When set to "false", the node(s) designated by the XPath expression will be replaced, rather than its/their contents.

Please let me know if you consider this useful, and if such an extension is being worked on - otherwise, I might like to look into creating and submitting a patch ... though I suspect that adding the parameter and replacing line XmlPokeTask.cs:300 with something like

```c#
if (replaceContents) {
node.InnerXml = value;
} else {
StringBuilder newInnerXml = new StringBuilder();
foreach (XmlNode currentNode in node.ParentNode.ChildNodes) {
if (currentNode == node) {
newInnerXml.Append(value);
} else {
newInnerXml.Append(currentNode.OuterXml);
}
}
node.ParentNode.InnerXml = newInnerXml.ToString();
}
```

might be all that's needed.

Thanks a lot!