return replaceNode((Element) self.item(0), c);
}
public static Element replaceNode(Element self, Closure c) {
// Use DOMBuilder to generate the replacement node.
DOMBuilder b = new DOMBuilder(self.getOwnerDocument());
Element newNode = (Element) b.invokeMethod("rootNode", c);
// The replacement node is the first child element of 'rootNode'.
Node n = newNode.getFirstChild();
while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
n = n.getNextSibling();