當前位置: 首頁>>代碼示例>>Java>>正文


Java Node.parent方法代碼示例

本文整理匯總了Java中org.jsoup.nodes.Node.parent方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.parent方法的具體用法?Java Node.parent怎麽用?Java Node.parent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jsoup.nodes.Node的用法示例。


在下文中一共展示了Node.parent方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPath

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
public String getPath(Node n)
{
    String nodePath = "";
    while (n != null) {
        if (n instanceof TextNode) {
            n = n.parent();
        }
        if (NodeHelper.isInnerText(n)) {
            n = n.parent();
        }
        String parentNodeName = n.nodeName();
        nodePath = parentNodeName + "." + nodePath;

        if (!parentNodeName.equalsIgnoreCase("html")) {
            n = n.parent();
        }
        else {
            break;
        }
    }

    return nodePath;
}
 
開發者ID:UKPLab,項目名稱:sigir2016-collection-for-focused-retrieval,代碼行數:24,代碼來源:Paragraph.java

示例2: isAncestor

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
 * Returns true if node1 is ancestor of node2 or node1 == node2
 *
 * @param node1 node 1
 * @param node2 node 2
 * @return boolean value
 */
public static boolean isAncestor(Node node1, Node node2)
{
    if (node1 == node2) {
        return true;
    }
    Node ancestor = node2;

    while (ancestor != null) {
        if (ancestor == node1) {
            return true;
        }
        ancestor = ancestor.parent();
    }

    return false;
}
 
開發者ID:dkpro,項目名稱:dkpro-c4corpus,代碼行數:24,代碼來源:NodeHelper.java

示例3: getIndexInParent

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
@Override
public Index getIndexInParent(final Node node, final boolean byType) {
	String type = byType ? getName(node) : Selector.UNIVERSAL_TAG;

	List<? extends Node> children;
	Node parent = node.parent();
	if (parent==null)
		children = Collections.emptyList();
	else
		children = getChildNodes(parent, type);

	return new Index(children.indexOf(node), children.size());
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:14,代碼來源:JsoupNodeHelper.java

示例4: getAncestorStateOfBranch

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
 * Visit from node to the ancestor - if all the visited ancestors are
 * {@link NodeHelper.TagType#INNERTEXT} returns
 * {@link ParagraphsExplorer.AncestorState#INNERTEXT_ONLY} - if one of the
 * visited ancestors is {@link NodeHelper#isBlockTag(Node)}
 * returns {@link ParagraphsExplorer.AncestorState#BLOCKLEVEL} - otherwise
 * returns {@link ParagraphsExplorer.AncestorState#UNKNOW}
 */
private static AncestorState getAncestorStateOfBranch(Node ancestor, Node node)
{
    if (!NodeHelper.isAncestor(ancestor, node)) {
        throw new InvalidParameterException("ancestor pre-condition violation");
    }
    if (node == ancestor) {
        if (NodeHelper.isBlockTag(node)) {
            return AncestorState.BLOCKLEVEL;
        }
        if (NodeHelper.isInlineTag(node)) {
            return AncestorState.INNERTEXT_ONLY;
        }
        return AncestorState.UNKNOW;
    }
    Node n = node.parent();
    boolean innerTextOnly = true;
    while (n != ancestor && n != null) {
        if (NodeHelper.isBlockTag(n)) {
            return AncestorState.BLOCKLEVEL;
        }
        if (!NodeHelper.isInlineTag(n)) {
            innerTextOnly = false;
        }
        n = n.parent();
    }
    return innerTextOnly ? AncestorState.INNERTEXT_ONLY : AncestorState.UNKNOW;
}
 
開發者ID:UKPLab,項目名稱:sigir2016-collection-for-focused-retrieval,代碼行數:36,代碼來源:ParagraphsExplorer.java

示例5: nearestCommonAncestor

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
 * Returns the nearest common ancestor of node1 and node2
 *
 * @param node1 node 1
 * @param node2 node 2
 * @return nearest common ancestor node
 * @throws IllegalStateException if node1 and node2 has no common ancestor
 *                               to make sure that node1 and node2 should inside the same document
 */
public static Node nearestCommonAncestor(Node node1, Node node2)
{
    Node ancestor = node1;
    while (ancestor != null) {
        if (isAncestor(ancestor, node2)) {
            return ancestor;
        }
        ancestor = ancestor.parent();
    }
    throw new IllegalStateException("node1 and node2 do not have common ancestor");
}
 
開發者ID:dkpro,項目名稱:dkpro-c4corpus,代碼行數:21,代碼來源:NodeHelper.java

示例6: isLink

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
 * Returns true if node has a link ancestor
 *
 * @param node node
 * @return boolean value
 */
public static boolean isLink(Node node)
{
    Node ancestor = node;

    while (ancestor != null) {
        if (isLinkTag(ancestor)) {
            return true;
        }
        ancestor = ancestor.parent();
    }

    return false;
}
 
開發者ID:dkpro,項目名稱:dkpro-c4corpus,代碼行數:20,代碼來源:NodeHelper.java

示例7: getAncestorStateOfBranch

import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
 * Visit from node to the ancestor - if all the visited ancestors are
 * {@link NodeHelper.TagType#INNER_TEXT} returns
 * {@link ParagraphsExplorer.AncestorState#INNERTEXT_ONLY} - if one of the
 * visited ancestors is {@link NodeHelper#isBlockTag(Node)}
 * returns {@link ParagraphsExplorer.AncestorState#BLOCKLEVEL} - otherwise
 * returns {@link ParagraphsExplorer.AncestorState#UNKNOW}
 */
private static AncestorState getAncestorStateOfBranch(Node ancestor, Node node)
{
    if (!NodeHelper.isAncestor(ancestor, node)) {
        throw new InvalidParameterException("ancestor pre-condition violation");
    }
    if (node == ancestor) {
        if (NodeHelper.isBlockTag(node)) {
            return AncestorState.BLOCKLEVEL;
        }
        if (NodeHelper.isInlineTag(node)) {
            return AncestorState.INNERTEXT_ONLY;
        }
        return AncestorState.UNKNOW;
    }
    Node n = node.parent();
    boolean innerTextOnly = true;
    while (n != ancestor && n != null) {
        if (NodeHelper.isBlockTag(n)) {
            return AncestorState.BLOCKLEVEL;
        }
        if (!NodeHelper.isInlineTag(n)) {
            innerTextOnly = false;
        }
        n = n.parent();
    }
    return innerTextOnly ? AncestorState.INNERTEXT_ONLY : AncestorState.UNKNOW;
}
 
開發者ID:dkpro,項目名稱:dkpro-c4corpus,代碼行數:36,代碼來源:ParagraphsExplorer.java


注:本文中的org.jsoup.nodes.Node.parent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。