protected Node[] childNodesAsArray() { return ensureChildNodes().toArray(new Node[childNodeSize()]); }
/** * Create a stand-alone, deep copy of this node, and all of its children. The cloned node will have no siblings or * parent node. As a stand-alone object, any changes made to the clone or any of its children will not impact the * original node. * <p> * The cloned node may be adopted into another Document or node structure using {@link Element#appendChild(Node)}. * @return a stand-alone cloned node, including clones of any children * @see #shallowClone() */ @Override public Node clone() { Node thisClone = doClone(null); // splits for orphan // Queue up nodes that need their children cloned (BFS). final LinkedList<Node> nodesToProcess = new LinkedList<>(); nodesToProcess.add(thisClone); while (!nodesToProcess.isEmpty()) { Node currParent = nodesToProcess.remove(); final int size = currParent.childNodeSize(); for (int i = 0; i < size; i++) { final List<Node> childNodes = currParent.ensureChildNodes(); Node childClone = childNodes.get(i).doClone(currParent); childNodes.set(i, childClone); nodesToProcess.add(childClone); } } return thisClone; }
private Element findFirstElementByTagName(String tag, Node node) { if (node.nodeName().equals(tag)) return (Element) node; else { int size = node.childNodeSize(); for (int i = 0; i < size; i++) { Element found = findFirstElementByTagName(tag, node.childNode(i)); if (found != null) return found; } } return null; }
/** * Start a depth-first traverse of the root and all of its descendants. * @param visitor Node visitor. * @param root the root node point to traverse. */ public static void traverse(NodeVisitor visitor, Node root) { Node node = root; int depth = 0; while (node != null) { visitor.head(node, depth); if (node.childNodeSize() > 0) { node = node.childNode(0); depth++; } else { while (node.nextSibling() == null && depth > 0) { visitor.tail(node, depth); node = node.parentNode(); depth--; } visitor.tail(node, depth); if (node == root) break; node = node.nextSibling(); } } }
if (headResult == HeadFilterDecision.CONTINUE && node.childNodeSize() > 0) { node = node.childNode(0); ++depth;
return result; if (result == FilterResult.CONTINUE && node.childNodeSize() > 0) { node = node.childNode(0); ++depth;
break; case P: if (item.childNodeSize() > 0) { processListItem(out, (Element) item, listState); } else {
int nodeCount = node.parent().childNodeSize(); if (node.parent().childNode(nodeCount - 1) == node) { transferIdToParent();
private static void removeCommentsRecursively(Node node) { int i = 0; while (i < node.childNodeSize()) { Node child = node.childNode(i); if (child instanceof Comment) { child.remove(); } else { removeCommentsRecursively(child); i++; } } }
if (parent.childNodeSize() > 0) { int index = 0; Node node1 = null; while (node1 == null && index < parent.childNodeSize()) { node1 = parent.childNode(index++); if (node.equals(node1)) {
if (root.childNodeSize() > 0) { for (final Node node : root.childNodes()) { walk(builder, node, depth + 1, captureText);
if (root.childNodeSize() > 0) { for (final Node node : root.childNodes()) { walk(builder, node, depth + 1, captureText);
public void traverse(Node root) { Node node = root; int depth = 0; while (node != null) { if (filter(node) || replace(node)) { node = node.nextSibling(); continue; } head(node, depth); if (node.childNodeSize() > 0) { node = node.childNode(0); depth++; } else { while (node.nextSibling() == null && depth > 0) { tail(node, depth); node = node.parentNode(); depth--; } tail(node, depth); if (node == root) { break; } node = node.nextSibling(); } } }