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();
}
}
}
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;
}