Java Code Examples for org.jsoup.nodes.Node#childNode()
The following examples show how to use
org.jsoup.nodes.Node#childNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLJsoupCleanerImpl.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * Remove the comments of the page * * @param node */ private void removeMalformedAttributes(Node node) { // as we are removing child nodes while iterating, we cannot use a normal foreach over children, // or will get a concurrent list modification error. int i = 0; while (i < node.childNodes().size()) { Node child = node.childNode(i); for (Attribute attr : child.attributes()) { if (attr.getKey().startsWith("\"") && attr.getKey().endsWith("\"")) { child.removeAttr(attr.getKey()); } } removeMalformedAttributes(child); i++; } }
Example 2
Source File: NodeTraversor.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Start a depth-first traverse of the root and all of its descendants. * @param root the root node point to traverse. */ public void traverse(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(); } } }
Example 3
Source File: NodeTraversor.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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(); } } }
Example 4
Source File: NodeTraversor.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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(); } } }
Example 5
Source File: NodeTraversor.java From jsoup-learning with MIT License | 6 votes |
/** * Start a depth-first traverse of the root and all of its descendants. * @param root the root node point to traverse. */ public void traverse(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.parent(); depth--; } visitor.tail(node, depth); if (node == root) break; node = node.nextSibling(); } } }
Example 6
Source File: HTMLJsoupCleanerImpl.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
/** * Remove the comments of the page * * @param node */ private void removeComments(Node node) { // as we are removing child nodes while iterating, we cannot use a normal foreach over children, // or will get a concurrent list modification error. int i = 0; while (i < node.childNodes().size()) { Node child = node.childNode(i); if (child.nodeName().equals("#comment")) child.remove(); else { removeComments(child); i++; } } }
Example 7
Source File: JsoupUtils.java From flow with Apache License 2.0 | 5 votes |
/** * Removes all comments from the {@code node} tree. * * @param node * a Jsoup node */ 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++; } } }