Here you can find the source of replace(Node src, NodeList nodes)
Parameter | Description |
---|---|
src | a parameter |
nodes | a parameter |
public static Node replace(Node src, NodeList nodes)
//package com.java2s; //License from project: BSD License import java.util.ArrayList; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**//from w ww . j a v a 2 s .co m * * @param src * @param nodes * @return the first remplaced Node */ public static Node replace(Node src, NodeList nodes) { Document doc = src.getOwnerDocument(); Node parent = src.getParentNode(); ArrayList<Node> copy = new ArrayList<Node>(); for (int i = 0; i < nodes.getLength(); i++) copy.add(nodes.item(i)); Node sibling = src.getNextSibling(); parent.removeChild(src); Node last = sibling; Node first = null; if (sibling == null) { for (Node n : copy) { last = parent.appendChild(doc.adoptNode(n)); if (first == null) first = last; } } else { for (Node n : copy) { last = parent.insertBefore(doc.adoptNode(n), sibling); if (first == null) first = last; } } return first; } }