当前位置: 首页>>代码示例>>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;未经允许,请勿转载。