Here you can find the source of replaceXPathNode(Node replaceThis, Node replaceWith)
public static void replaceXPathNode(Node replaceThis, Node replaceWith) throws XPathExpressionException
//package com.java2s; /*/*from ww w . j ava2 s . c om*/ 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); } }