Search in sources :

Example 1 with Node

use of com.jsoup.nodes.Node in project User-Behavior-in-Facebook by abozanona.

the class NodeTraversor method traverse.

public void traverse(Node root) {
    Node node = root;
    int depth = 0;
    while (node != null) {
        visitor.head(node, depth);
        if (node.childNodes().size() > 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();
        }
    }
}
Also used : Node(com.jsoup.nodes.Node)

Example 2 with Node

use of com.jsoup.nodes.Node in project User-Behavior-in-Facebook by abozanona.

the class Parser method parseBodyFragment.

/**
 * Parse a fragment of HTML into the {@code body} of a Document.
 *
 * @param bodyHtml fragment of HTML
 * @param baseUri base URI of document (i.e. original fetch location), for resolving relative URLs.
 *
 * @return Document, with empty head, and HTML parsed into body
 */
public static Document parseBodyFragment(String bodyHtml, String baseUri) {
    Document doc = Document.createShell(baseUri);
    Element body = doc.body();
    List<Node> nodeList = parseFragment(bodyHtml, body, baseUri);
    // the node list gets modified when re-parented
    Node[] nodes = nodeList.toArray(new Node[nodeList.size()]);
    for (Node node : nodes) {
        body.appendChild(node);
    }
    return doc;
}
Also used : Element(com.jsoup.nodes.Element) Node(com.jsoup.nodes.Node) Document(com.jsoup.nodes.Document)

Aggregations

Node (com.jsoup.nodes.Node)2 Document (com.jsoup.nodes.Document)1 Element (com.jsoup.nodes.Element)1