org.jsoup.nodes.Node#nextSibling ( )源码实例Demo

下面列出了org.jsoup.nodes.Node#nextSibling ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: astor   文件: NodeTraversor.java
/**
 * 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();
        }
    }
}
 
源代码2 项目: astor   文件: NodeTraversor.java
/**
 * 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();
        }
    }
}
 
源代码3 项目: astor   文件: NodeTraversor.java
/**
 * 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();
        }
    }
}
 
源代码4 项目: jsoup-learning   文件: NodeTraversor.java
/**
 * 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();
        }
    }
}
 
源代码5 项目: FairEmail   文件: HtmlHelper.java
static void convertLists(Document document) {
    for (Element span : document.select("span")) {
        // Skip signature and referenced message
        boolean body = true;
        Element parent = span.parent();
        while (parent != null) {
            if ("div".equals(parent.tagName()) &&
                    !TextUtils.isEmpty(parent.attr("fairemail"))) {
                body = false;
                break;
            }
            parent = parent.parent();
        }
        if (!body)
            continue;

        Element list = null;
        for (int i = 0; i < span.childNodeSize(); i++) {
            boolean item = false;
            Node node = span.childNode(i);
            if (node instanceof TextNode) {
                String text = ((TextNode) node).text().trim();
                Node next = node.nextSibling();
                if ((text.startsWith("* ") || text.startsWith("- ")) &&
                        (next == null || "br".equals(next.nodeName()))) {
                    item = true;
                    String type = (text.startsWith("* ") ? "ul" : "ol");

                    Element li = document.createElement("li");
                    li.text(text.substring(2));

                    if (list == null || !list.tagName().equals(type)) {
                        Node before = node.previousSibling();
                        if (before != null && "br".equals(before.nodeName())) {
                            before.remove();
                            i--;
                        }

                        list = document.createElement(type);
                        list.appendChild(li);
                        node.replaceWith(list);

                    } else {
                        list.appendChild(li);
                        node.remove();
                        i--;
                    }

                    if (next != null)
                        next.remove();
                }
            } else {
                if (list != null && "br".equals(node.nodeName())) {
                    node.remove();
                    i--;
                }
            }
            if (!item)
                list = null;
        }
    }
}