本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}