Java tutorial
//package com.java2s; /* Copyright (c) 2009-2011, AOL Inc. All rights reserved. This code is licensed under a BSD license. Howard Uman */ import javax.xml.xpath.XPathExpressionException; import org.w3c.dom.Node; public class Main { public static void replaceXPathNode(Node replaceThis, Node replaceWith) throws XPathExpressionException { Node parentNode = replaceThis.getParentNode(); parentNode.insertBefore(replaceWith, replaceThis); parentNode.removeChild(replaceThis); } }