当前位置: 首页>>代码示例>>Java>>正文


Java Element.getPreviousSibling方法代码示例

本文整理汇总了Java中org.w3c.dom.Element.getPreviousSibling方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getPreviousSibling方法的具体用法?Java Element.getPreviousSibling怎么用?Java Element.getPreviousSibling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Element的用法示例。


在下文中一共展示了Element.getPreviousSibling方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasSiblingBefore

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static boolean hasSiblingBefore(Element element) {
    Node sibling = element.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            return true;
        }
        sibling = sibling.getPreviousSibling();
    }
    return false;
}
 
开发者ID:i49,项目名称:cascade,代码行数:11,代码来源:Elements.java

示例2: hasSameTypeBefore

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static boolean hasSameTypeBefore(Element element) {
    Node sibling = element.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            if (isSameType(element, (Element)sibling)) {
                return true;
            }
        }
        sibling = sibling.getPreviousSibling();
    }
    return false;
}
 
开发者ID:i49,项目名称:cascade,代码行数:13,代码来源:Elements.java

示例3: countSiblingsBefore

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static int countSiblingsBefore(Element element) {
    int count = 0;
    Node sibling = element.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            ++count;
        }
        sibling = sibling.getPreviousSibling();
    }
    return count;
}
 
开发者ID:i49,项目名称:cascade,代码行数:12,代码来源:Elements.java

示例4: countSameTypeBefore

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static int countSameTypeBefore(Element element) {
    int count = 0;
    Node sibling = element.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            if (isSameType(element, (Element)sibling)) {
                ++count;
            }
        }
        sibling = sibling.getPreviousSibling();
    }
    return count;
}
 
开发者ID:i49,项目名称:cascade,代码行数:14,代码来源:Elements.java

示例5: test

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public boolean test(Element start, Element root) {
    Node sibling = start.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element)sibling;
            if (test(element) && testPrevious(element, root)) {
                return true;
            }
        }
        sibling = sibling.getPreviousSibling();
    }
    return false;
}
 
开发者ID:i49,项目名称:cascade,代码行数:15,代码来源:SiblingSequence.java

示例6: test

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public boolean test(Element start, Element root) {
    Node sibling = start.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element)sibling;
            if (test(element) && testPrevious(element, root)) {
                return true;
            }
            return false;
        }
        sibling = sibling.getPreviousSibling();
    }
    return false;
}
 
开发者ID:i49,项目名称:cascade,代码行数:16,代码来源:AdjacentSequence.java

示例7: newlineBeforeElementOpen

import org.w3c.dom.Element; //导入方法依赖的package包/类
private boolean newlineBeforeElementOpen(Element element, int depth) {
    if (hasBlankLineAbove()) {
        return false;
    }

    if (mPrefs.removeEmptyLines || depth <= 0) {
        return false;
    }

    if (isMarkupElement(element)) {
        return false;
    }

    // See if this element should be separated from the previous element.
    // This is the case if we are not compressing whitespace (checked above),
    // or if we are not immediately following a comment (in which case the
    // newline would have been added above it), or if we are not in a formatting
    // style where
    if (mStyle == XmlFormatStyle.LAYOUT) {
        // In layouts we always separate elements
        return true;
    }

    if (mStyle == XmlFormatStyle.MANIFEST || mStyle == XmlFormatStyle.RESOURCE
            || mStyle == XmlFormatStyle.FILE) {
        Node curr = element.getPreviousSibling();

        // <style> elements are traditionally separated unless it follows a comment
        if (TAG_STYLE.equals(element.getTagName())) {
            if (curr == null
                    || curr.getNodeType() == Node.ELEMENT_NODE
                    || (curr.getNodeType() == Node.TEXT_NODE
                    && curr.getNodeValue().trim().isEmpty()
                    && (curr.getPreviousSibling() == null
                    || curr.getPreviousSibling().getNodeType()
                    == Node.ELEMENT_NODE))) {
                return true;
            }
        }

        // In all other styles, we separate elements if they have a different tag than
        // the previous one (but we don't insert a newline inside tags)
        while (curr != null) {
            short nodeType = curr.getNodeType();
            if (nodeType == Node.ELEMENT_NODE) {
                Element sibling = (Element) curr;
                if (!element.getTagName().equals(sibling.getTagName())) {
                    return true;
                }
                break;
            } else if (nodeType == Node.TEXT_NODE) {
                String text = curr.getNodeValue();
                if (!text.trim().isEmpty()) {
                    break;
                }
                // If there is just whitespace, continue looking for a previous sibling
            } else {
                // Any other previous node type, such as a comment, means we don't
                // continue looking: this element should not be separated
                break;
            }
            curr = curr.getPreviousSibling();
        }
        if (curr == null && depth <= 1) {
            // Insert new line inside tag if it's the first element inside the root tag
            return true;
        }

        return false;
    }

    return false;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:74,代码来源:XmlPrettyPrinter.java


注:本文中的org.w3c.dom.Element.getPreviousSibling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。