org.w3c.dom.Node.getPreviousSibling()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.w3c.dom.Node.getPreviousSibling()方法的一些代码示例,展示了Node.getPreviousSibling()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getPreviousSibling()方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:getPreviousSibling

Node.getPreviousSibling介绍

[英]The node immediately preceding this node. If there is no such node, this returns null.
[中]紧靠此节点之前的节点。如果没有这样的节点,则返回null

代码示例

代码示例来源:origin: marytts/marytts

/**
 * Get the previous sibling of <code>e</code> which is an element, or <code>null</code> if there is no such element.
 * 
 * @param e
 *            e
 * @return null if n is null, true otherwise
 */
public static Element getPreviousSiblingElement(Element e) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getPreviousSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE)
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: marytts/marytts

/**
 * Get the previous sibling of <code>e</code> which is an element, or <code>null</code> if there is no such element.
 * 
 * @param e
 *            e
 * @return null if n is null, true otherwise
 */
public static Element getPreviousSiblingElement(Element e) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getPreviousSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE)
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: marytts/marytts

/**
 * Get the previous sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
 * there is no such element.
 * 
 * @param e
 *            e
 * @param name
 *            name
 * @return null if n is null
 */
public static Element getPreviousSiblingElementByTagName(Element e, String name) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getPreviousSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: marytts/marytts

/**
 * Get the previous sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
 * there is no such element.
 * 
 * @param e
 *            e
 * @param name
 *            name
 * @return null if n is null
 */
public static Element getPreviousSiblingElementByTagName(Element e, String name) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getPreviousSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the first text or CDATA node in the current sequence of text and
 * CDATA nodes.
 */
private TextImpl firstTextNodeInCurrentRun() {
  TextImpl firstTextInCurrentRun = this;
  for (Node p = getPreviousSibling(); p != null; p = p.getPreviousSibling()) {
    short nodeType = p.getNodeType();
    if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) {
      firstTextInCurrentRun = (TextImpl) p;
    } else {
      break;
    }
  }
  return firstTextInCurrentRun;
}

代码示例来源:origin: marytts/marytts

/**
 * Get the last child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
 * 
 * @param e
 *            e
 * @return n
 */
public static Element getLastChildElement(Element e) {
  Node n = e.getLastChild();
  while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
    n = n.getPreviousSibling();
  }
  // Now n is either null or an Element
  return (Element) n;
}

代码示例来源:origin: marytts/marytts

/**
 * Get the last child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
 * 
 * @param e
 *            e
 * @return n
 */
public static Element getLastChildElement(Element e) {
  Node n = e.getLastChild();
  while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
    n = n.getPreviousSibling();
  }
  // Now n is either null or an Element
  return (Element) n;
}

代码示例来源:origin: plutext/docx4j

private void closeElements (Node node) throws IOException {
 Node prev = (node == null) ? null : node.getPreviousSibling (), next;
 if (((node == null) && !elements.isEmpty ()) ||
   ((prev != null) && (prev.getNodeType () == Node.ELEMENT_NODE))) {
  Iterator i = elements.iterator ();
  do {
   next = (Node) i.next ();
   i.remove ();
   if (elementOpened) {
    writer.write (" />");
    elementOpened = false;
    } else {
     writer.write ("</" + next.getNodeName () + ">");
    }
  } while (i.hasNext () && (next != prev));
 } else if (elementOpened && (node.getNodeType () != Node.ATTRIBUTE_NODE)) {
  writer.write (">");
  elementOpened = false;
 }
}

代码示例来源:origin: org.freemarker/freemarker

for (int i = 0; i < size; i++) {
  NodeModel child = (NodeModel) children.get(i);
  if (child.node.getNodeType() == Node.ELEMENT_NODE) {
    ns.add(child);
    return new SimpleScalar(buf.toString().trim());
  } else if (key.equals(AtAtKey.PREVIOUS_SIBLING_ELEMENT.getKey())) {
    Node previousSibling = node.getPreviousSibling();
    while (previousSibling != null && !this.isSignificantNode(previousSibling)) {
      previousSibling = previousSibling.getPreviousSibling();
    return previousSibling != null && previousSibling.getNodeType() == Node.ELEMENT_NODE
        ? wrap(previousSibling) : new NodeListModel(Collections.emptyList(), null);  
  } else if (key.equals(AtAtKey.NEXT_SIBLING_ELEMENT.getKey())) {
      nextSibling = nextSibling.getNextSibling();
    return nextSibling != null && nextSibling.getNodeType() == Node.ELEMENT_NODE
        ? wrap(nextSibling) : new NodeListModel(Collections.emptyList(), null);  
  } else {

代码示例来源:origin: wsdl4j/wsdl4j

private static Node getPreviousTypedNode(Node node, short nodeType)
{
 node = node.getPreviousSibling();
 while (node != null && node.getNodeType() != nodeType)
 {
  node = node.getPreviousSibling();
 }
 return node;
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static Element getPrevSibling(Element e) {
 Node n = e.getPreviousSibling();
 while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  n = n.getPreviousSibling();
 return (Element) n;
}

代码示例来源:origin: jamesagnew/hapi-fhir

public Element getlastChild(Element e) {
  Node n = e.getLastChild();
  while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
    n = n.getPreviousSibling();
  return n == null ? null : (Element) n;
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static Element getLastChild(Element e) {
 if (e == null)
  return null;
 Node n = e.getLastChild();
 while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  n = n.getPreviousSibling();
 return (Element) n;
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static Element getLastChild(Element e) {
 if (e == null)
  return null;
 Node n = e.getLastChild();
 while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  n = n.getPreviousSibling();
 return (Element) n;
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static Element getPrevSibling(Element e) {
 Node n = e.getPreviousSibling();
 while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  n = n.getPreviousSibling();
 return (Element) n;
}

代码示例来源:origin: jamesagnew/hapi-fhir

private void reapComments(org.w3c.dom.Element element, Element context) {
 Node node = element.getPreviousSibling();
 while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
   if (node.getNodeType() == Node.COMMENT_NODE)
     context.getComments().add(0, node.getTextContent());
   node = node.getPreviousSibling();
 }
  node = element.getLastChild();
  while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
    node = node.getPreviousSibling();
  }
  while (node != null) {
    if (node.getNodeType() == Node.COMMENT_NODE)
      context.getComments().add(node.getTextContent());
    node = node.getNextSibling();
  }
}

代码示例来源:origin: jamesagnew/hapi-fhir

private void reapComments(org.w3c.dom.Element element, Element context) {
  Node node = element.getPreviousSibling();
  while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
    if (node.getNodeType() == Node.COMMENT_NODE)
      context.getComments().add(0, node.getTextContent());
    node = node.getPreviousSibling();
  }
  node = element.getLastChild();
  while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
    node = node.getPreviousSibling();
  }
  while (node != null) {
    if (node.getNodeType() == Node.COMMENT_NODE)
      context.getComments().add(node.getTextContent());
    node = node.getNextSibling();
  }
}

代码示例来源:origin: org.eclipse.che.core/che-core-commons-xml

private Node previousElementNode(Node node) {
 node = node.getPreviousSibling();
 while (node != null && node.getNodeType() != ELEMENT_NODE) {
  node = node.getPreviousSibling();
 }
 return node;
}

代码示例来源:origin: org.apache.woden/woden-impl-dom

private static Node getPreviousTypedNode(Node node, short nodeType)
{
 node = node.getPreviousSibling();
 while (node != null && node.getNodeType() != nodeType)
 {
  node = node.getPreviousSibling();
 }
 return node;
}

代码示例来源:origin: com.android.tools.lint/lint-checks

private static boolean isFirstElementChild(Node node) {
  node = node.getPreviousSibling();
  while (node != null) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
      return false;
    }
    node = node.getPreviousSibling();
  }
  return true;
}

相关文章