/** * Returns a child node with given hierarchy. * Just a shortcut for successive calls of {@link #getChild(int)}. */ public Node getChild(final int... indexes) { Node node = this; for (int index : indexes) { node = node.getChild(index); } return node; }
/** * Initializes list of child elements. */ protected void initChildElementNodes() { if (childElementNodes == null) { childElementNodes = new Element[childElementNodesCount]; int childCount = getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node child = getChild(i); if (child.siblingElementIndex >= 0) { childElementNodes[child.siblingElementIndex] = (Element) child; } } } }
/** * Changes owner document for given node and all its children. */ protected void changeOwnerDocument(final Node node, final Document ownerDocument) { node.ownerDocument = ownerDocument; int childCount = node.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node child = node.getChild(i); changeOwnerDocument(child, ownerDocument); } }
@Test void testCombinators() throws IOException { NodeSelector nodeSelector = createNodeFilter(); List<Node> nodes = nodeSelector.select("p#text > span"); assertEquals(1, nodes.size()); Node spanNode = nodes.get(0); assertEquals("spanner", (spanNode.getChild(0)).getNodeValue()); nodes = nodeSelector.select("p#text > em"); assertEquals(3, nodes.size()); nodes = nodeSelector.select("p#text > em#oleg + em"); assertEquals(0, nodes.size()); nodes = nodeSelector.select("p#text > em#oleg + span"); assertEquals(1, nodes.size()); assertEquals("spanner", (nodes.get(0).getChild(0)).getNodeValue()); nodes = nodeSelector.select("p#text > em#oleg ~ em"); assertEquals(1, nodes.size()); assertEquals("lina", nodes.get(0).getAttribute(0).getValue()); }
/** * Walks over the child notes, maintaining the tree order and not using recursion. */ protected void walkDescendantsIteratively(final LinkedList<Node> nodes, final CssSelector cssSelector, final List<Node> result) { while (!nodes.isEmpty()) { Node node = nodes.removeFirst(); selectAndAdd(node, cssSelector, result); // append children in walking order to be processed right after this node int childCount = node.getChildNodesCount(); for (int i = childCount - 1; i >= 0; i--) { nodes.addFirst(node.getChild(i)); } } }
protected void walk(final Node rootNode, final NodeFilter nodeFilter, final List<Node> result) { int childCount = rootNode.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node node = rootNode.getChild(i); if (nodeFilter.accept(node)) { result.add(node); } walk(node, nodeFilter, result); } }
/** * Returns a child node with given hierarchy. * Just a shortcut for successive calls of {@link #getChild(int)}. */ public Node getChild(final int... indexes) { Node node = this; for (int index : indexes) { node = node.getChild(index); } return node; }
Node child = getChild(i); if (child.siblingElementIndex >= 0) { if (childElementNodes[child.siblingElementIndex] != child) {
/** * Returns a child node with given hierarchy. * Just a shortcut for successive calls of {@link #getChild(int)}. */ public Node getChild(int... indexes) { Node node = this; for (int index : indexes) { node = node.getChild(index); } return node; }
int childs = node.getChildNodesCount(); for (int i = 0; i < childs; i++) { Node childNode = node.getChild(i);
@Test void test233() { String html = "<div><span>name</span>value</div>"; Jerry $ = Jerry.jerry(html); assertEquals("namevalue", $.text()); assertEquals(1, $.children().size()); Node div = $.children().get(0); assertEquals("div", div.getNodeName()); assertEquals(2, div.getChildNodesCount()); assertEquals("value", div.getChild(1).getNodeValue()); }
/** * Initializes list of child elements. */ protected void initChildElementNodes() { if (childElementNodes == null) { childElementNodes = new Element[childElementNodesCount]; int childCount = getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node child = getChild(i); if (child.siblingElementIndex >= 0) { childElementNodes[child.siblingElementIndex] = (Element) child; } } } }
/** * Changes owner document for given node and all its children. */ protected void changeOwnerDocument(Node node, Document ownerDocument) { node.ownerDocument = ownerDocument; int childCount = node.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node child = node.getChild(i); changeOwnerDocument(child, ownerDocument); } }
/** * Changes owner document for given node and all its children. */ protected void changeOwnerDocument(final Node node, final Document ownerDocument) { node.ownerDocument = ownerDocument; int childCount = node.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node child = node.getChild(i); changeOwnerDocument(child, ownerDocument); } }
/** * Walks over the child notes, maintaining the tree order and not using recursion. */ protected void walkDescendantsIteratively(final LinkedList<Node> nodes, final CssSelector cssSelector, final List<Node> result) { while (!nodes.isEmpty()) { Node node = nodes.removeFirst(); selectAndAdd(node, cssSelector, result); // append children in walking order to be processed right after this node int childCount = node.getChildNodesCount(); for (int i = childCount - 1; i >= 0; i--) { nodes.addFirst(node.getChild(i)); } } }
protected void walk(final Node rootNode, final NodeFilter nodeFilter, final List<Node> result) { int childCount = rootNode.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node node = rootNode.getChild(i); if (nodeFilter.accept(node)) { result.add(node); } walk(node, nodeFilter, result); } }
protected void walk(Node rootNode, NodeFilter nodeFilter, LinkedList<Node> result) { int childCount = rootNode.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node node = rootNode.getChild(i); if (nodeFilter.accept(node)) { result.add(node); } walk(node, nodeFilter, result); } }
protected void walk(Node rootNode, NodeFilter nodeFilter, List<Node> result) { int childCount = rootNode.getChildNodesCount(); for (int i = 0; i < childCount; i++) { Node node = rootNode.getChild(i); if (nodeFilter.accept(node)) { result.add(node); } walk(node, nodeFilter, result); } }