/** * Creates a new NodeList containing the same elements as the * original (but cloned in the case of Nodes). * * @return the clone */ @Override public Object clone() { NodeList result = new NodeList(size()); for (int i = 0; i < size(); i++) { Object next = get(i); if (next instanceof Node) { Node n = (Node) next; result.add(n.clone()); } else { result.add(next); } } return result; }
/** * Selects correct path for multiple variants. If possible path node has assigned id, different with current * child id, then node can't be used. Only not used node selected (without id at all or with same id). * * @param list possible source paths * @param child child node to find path for * @return resolved path or null (in null case child should be simply appended to source xml) */ @Nullable private static Node findPath(NodeList list, Node child) { String childID = nid(child); Node firstNidNull = null; // look for matching id or any node without id for (int i = 0, size = list.size(); i < size; i++) { Node node = (Node) list.get(i); if (childID.equals(nid(node))) { return node; } if (firstNidNull == null && nid(node) == null) { firstNidNull = node; } } return firstNidNull; }