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

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

本文整理了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

  1. /**
  2. * Get the previous sibling of <code>e</code> which is an element, or <code>null</code> if there is no such element.
  3. *
  4. * @param e
  5. * e
  6. * @return null if n is null, true otherwise
  7. */
  8. public static Element getPreviousSiblingElement(Element e) {
  9. Node n = e;
  10. if (n == null)
  11. return null;
  12. while ((n = n.getPreviousSibling()) != null) {
  13. if (n.getNodeType() == Node.ELEMENT_NODE)
  14. return (Element) n;
  15. }
  16. return null;
  17. }

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

  1. /**
  2. * Get the previous sibling of <code>e</code> which is an element, or <code>null</code> if there is no such element.
  3. *
  4. * @param e
  5. * e
  6. * @return null if n is null, true otherwise
  7. */
  8. public static Element getPreviousSiblingElement(Element e) {
  9. Node n = e;
  10. if (n == null)
  11. return null;
  12. while ((n = n.getPreviousSibling()) != null) {
  13. if (n.getNodeType() == Node.ELEMENT_NODE)
  14. return (Element) n;
  15. }
  16. return null;
  17. }

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

  1. /**
  2. * Get the previous sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
  3. * there is no such element.
  4. *
  5. * @param e
  6. * e
  7. * @param name
  8. * name
  9. * @return null if n is null
  10. */
  11. public static Element getPreviousSiblingElementByTagName(Element e, String name) {
  12. Node n = e;
  13. if (n == null)
  14. return null;
  15. while ((n = n.getPreviousSibling()) != null) {
  16. if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
  17. return (Element) n;
  18. }
  19. return null;
  20. }

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

  1. /**
  2. * Get the previous sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
  3. * there is no such element.
  4. *
  5. * @param e
  6. * e
  7. * @param name
  8. * name
  9. * @return null if n is null
  10. */
  11. public static Element getPreviousSiblingElementByTagName(Element e, String name) {
  12. Node n = e;
  13. if (n == null)
  14. return null;
  15. while ((n = n.getPreviousSibling()) != null) {
  16. if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
  17. return (Element) n;
  18. }
  19. return null;
  20. }

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

  1. /**
  2. * Returns the first text or CDATA node in the current sequence of text and
  3. * CDATA nodes.
  4. */
  5. private TextImpl firstTextNodeInCurrentRun() {
  6. TextImpl firstTextInCurrentRun = this;
  7. for (Node p = getPreviousSibling(); p != null; p = p.getPreviousSibling()) {
  8. short nodeType = p.getNodeType();
  9. if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) {
  10. firstTextInCurrentRun = (TextImpl) p;
  11. } else {
  12. break;
  13. }
  14. }
  15. return firstTextInCurrentRun;
  16. }

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

  1. /**
  2. * Get the last child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
  3. *
  4. * @param e
  5. * e
  6. * @return n
  7. */
  8. public static Element getLastChildElement(Element e) {
  9. Node n = e.getLastChild();
  10. while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
  11. n = n.getPreviousSibling();
  12. }
  13. // Now n is either null or an Element
  14. return (Element) n;
  15. }

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

  1. /**
  2. * Get the last child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
  3. *
  4. * @param e
  5. * e
  6. * @return n
  7. */
  8. public static Element getLastChildElement(Element e) {
  9. Node n = e.getLastChild();
  10. while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
  11. n = n.getPreviousSibling();
  12. }
  13. // Now n is either null or an Element
  14. return (Element) n;
  15. }

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

  1. private void closeElements (Node node) throws IOException {
  2. Node prev = (node == null) ? null : node.getPreviousSibling (), next;
  3. if (((node == null) && !elements.isEmpty ()) ||
  4. ((prev != null) && (prev.getNodeType () == Node.ELEMENT_NODE))) {
  5. Iterator i = elements.iterator ();
  6. do {
  7. next = (Node) i.next ();
  8. i.remove ();
  9. if (elementOpened) {
  10. writer.write (" />");
  11. elementOpened = false;
  12. } else {
  13. writer.write ("</" + next.getNodeName () + ">");
  14. }
  15. } while (i.hasNext () && (next != prev));
  16. } else if (elementOpened && (node.getNodeType () != Node.ATTRIBUTE_NODE)) {
  17. writer.write (">");
  18. elementOpened = false;
  19. }
  20. }

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

  1. for (int i = 0; i < size; i++) {
  2. NodeModel child = (NodeModel) children.get(i);
  3. if (child.node.getNodeType() == Node.ELEMENT_NODE) {
  4. ns.add(child);
  5. return new SimpleScalar(buf.toString().trim());
  6. } else if (key.equals(AtAtKey.PREVIOUS_SIBLING_ELEMENT.getKey())) {
  7. Node previousSibling = node.getPreviousSibling();
  8. while (previousSibling != null && !this.isSignificantNode(previousSibling)) {
  9. previousSibling = previousSibling.getPreviousSibling();
  10. return previousSibling != null && previousSibling.getNodeType() == Node.ELEMENT_NODE
  11. ? wrap(previousSibling) : new NodeListModel(Collections.emptyList(), null);
  12. } else if (key.equals(AtAtKey.NEXT_SIBLING_ELEMENT.getKey())) {
  13. nextSibling = nextSibling.getNextSibling();
  14. return nextSibling != null && nextSibling.getNodeType() == Node.ELEMENT_NODE
  15. ? wrap(nextSibling) : new NodeListModel(Collections.emptyList(), null);
  16. } else {

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

  1. private static Node getPreviousTypedNode(Node node, short nodeType)
  2. {
  3. node = node.getPreviousSibling();
  4. while (node != null && node.getNodeType() != nodeType)
  5. {
  6. node = node.getPreviousSibling();
  7. }
  8. return node;
  9. }

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

  1. public static Element getPrevSibling(Element e) {
  2. Node n = e.getPreviousSibling();
  3. while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  4. n = n.getPreviousSibling();
  5. return (Element) n;
  6. }

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

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

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

  1. public static Element getLastChild(Element e) {
  2. if (e == null)
  3. return null;
  4. Node n = e.getLastChild();
  5. while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  6. n = n.getPreviousSibling();
  7. return (Element) n;
  8. }

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

  1. public static Element getLastChild(Element e) {
  2. if (e == null)
  3. return null;
  4. Node n = e.getLastChild();
  5. while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  6. n = n.getPreviousSibling();
  7. return (Element) n;
  8. }

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

  1. public static Element getPrevSibling(Element e) {
  2. Node n = e.getPreviousSibling();
  3. while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  4. n = n.getPreviousSibling();
  5. return (Element) n;
  6. }

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

  1. private void reapComments(org.w3c.dom.Element element, Element context) {
  2. Node node = element.getPreviousSibling();
  3. while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
  4. if (node.getNodeType() == Node.COMMENT_NODE)
  5. context.getComments().add(0, node.getTextContent());
  6. node = node.getPreviousSibling();
  7. }
  8. node = element.getLastChild();
  9. while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
  10. node = node.getPreviousSibling();
  11. }
  12. while (node != null) {
  13. if (node.getNodeType() == Node.COMMENT_NODE)
  14. context.getComments().add(node.getTextContent());
  15. node = node.getNextSibling();
  16. }
  17. }

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

  1. private void reapComments(org.w3c.dom.Element element, Element context) {
  2. Node node = element.getPreviousSibling();
  3. while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
  4. if (node.getNodeType() == Node.COMMENT_NODE)
  5. context.getComments().add(0, node.getTextContent());
  6. node = node.getPreviousSibling();
  7. }
  8. node = element.getLastChild();
  9. while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
  10. node = node.getPreviousSibling();
  11. }
  12. while (node != null) {
  13. if (node.getNodeType() == Node.COMMENT_NODE)
  14. context.getComments().add(node.getTextContent());
  15. node = node.getNextSibling();
  16. }
  17. }

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

  1. private Node previousElementNode(Node node) {
  2. node = node.getPreviousSibling();
  3. while (node != null && node.getNodeType() != ELEMENT_NODE) {
  4. node = node.getPreviousSibling();
  5. }
  6. return node;
  7. }

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

  1. private static Node getPreviousTypedNode(Node node, short nodeType)
  2. {
  3. node = node.getPreviousSibling();
  4. while (node != null && node.getNodeType() != nodeType)
  5. {
  6. node = node.getPreviousSibling();
  7. }
  8. return node;
  9. }

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

  1. private static boolean isFirstElementChild(Node node) {
  2. node = node.getPreviousSibling();
  3. while (node != null) {
  4. if (node.getNodeType() == Node.ELEMENT_NODE) {
  5. return false;
  6. }
  7. node = node.getPreviousSibling();
  8. }
  9. return true;
  10. }

相关文章