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

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

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

Node.compareDocumentPosition介绍

[英]Compares the reference node, i.e. the node on which this method is being called, with a node, i.e. the one passed as a parameter, with regard to their position in the document and according to the document order.
[中]根据引用节点在文档中的位置和文档顺序,将引用节点(即调用此方法的节点)与节点(即作为参数传递的节点)进行比较。

代码示例

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

  1. @SuppressWarnings("PMD.AvoidUsingShortType")
  2. @Override
  3. public short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException {
  4. return node.compareDocumentPosition(other);
  5. }

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

  1. if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  2. throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");

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

  1. if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  2. throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");

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

  1. if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  2. throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");

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

  1. if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  2. throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");

代码示例来源:origin: fbacchella/jrds

  1. /**
  2. * @param other
  3. * @return
  4. * @throws org.w3c.dom.DOMException
  5. * @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node)
  6. */
  7. public short compareDocumentPosition(Node other) {
  8. return parent.compareDocumentPosition(other);
  9. }

代码示例来源:origin: org.jboss.ws.native/jbossws-native-core

  1. public short compareDocumentPosition(Node other) throws DOMException
  2. {
  3. return this.domNode.compareDocumentPosition(other);
  4. }

代码示例来源:origin: xyz.cofe/common

  1. @Override
  2. public short compareDocumentPosition(Node other) throws DOMException {
  3. return node.compareDocumentPosition(other);
  4. }

代码示例来源:origin: org.apache.axis2/axis2-saaj

  1. public final short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException {
  2. return target.compareDocumentPosition(other);
  3. }

代码示例来源:origin: apache/axis2-java

  1. public final short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException {
  2. return target.compareDocumentPosition(other);
  3. }

代码示例来源:origin: org.vx68k.quercus/quercus

  1. public short compareDocumentPosition(DOMNode other)
  2. throws DOMException
  3. {
  4. try {
  5. return _delegate.compareDocumentPosition(other.getDelegate());
  6. }
  7. catch (org.w3c.dom.DOMException ex) {
  8. throw wrap(ex);
  9. }
  10. }

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

  1. /**
  2. * Runs the test case.
  3. * @throws Throwable Any uncaught exception causes test to fail
  4. */
  5. public void runTest() throws Throwable {
  6. Document doc;
  7. NodeList elemList;
  8. Element elemName;
  9. Node entRef;
  10. int elementPosition;
  11. int entRefPosition;
  12. doc = (Document) load("hc_staff", false);
  13. elemList = doc.getElementsByTagName("var");
  14. elemName = (Element) elemList.item(2);
  15. entRef = elemName.getFirstChild();
  16. elementPosition = (int) elemName.compareDocumentPosition(entRef);
  17. assertEquals("nodecomparedocumentpositionIsContainedFollowing25", 20, elementPosition);
  18. entRefPosition = (int) entRef.compareDocumentPosition(elemName);
  19. assertEquals("nodecomparedocumentpositionContainsPRECEDING25", 10, entRefPosition);
  20. }
  21. /**

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

  1. /**
  2. * Returns the last selection range in the current document, by document position.
  3. * @return the last selection range in the current document, by document position
  4. */
  5. private Range getLastRange() {
  6. // avoid concurrent modification exception
  7. final List<Range> ranges = new ArrayList<>(getRanges());
  8. Range last = null;
  9. for (final Range range : ranges) {
  10. if (last == null) {
  11. last = range;
  12. }
  13. else {
  14. final org.w3c.dom.Node lastStart = last.getStartContainer();
  15. final org.w3c.dom.Node rangeStart = range.getStartContainer();
  16. if ((lastStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_FOLLOWING) != 0) {
  17. last = range;
  18. }
  19. }
  20. }
  21. return last;
  22. }

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

  1. /**
  2. * Returns the first selection range in the current document, by document position.
  3. * @return the first selection range in the current document, by document position
  4. */
  5. private Range getFirstRange() {
  6. // avoid concurrent modification exception
  7. final List<Range> ranges = new ArrayList<>(getRanges());
  8. Range first = null;
  9. for (final Range range : ranges) {
  10. if (first == null) {
  11. first = range;
  12. }
  13. else {
  14. final org.w3c.dom.Node firstStart = first.getStartContainer();
  15. final org.w3c.dom.Node rangeStart = range.getStartContainer();
  16. if ((firstStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
  17. first = range;
  18. }
  19. }
  20. }
  21. return first;
  22. }

代码示例来源:origin: HtmlUnit/htmlunit

  1. /**
  2. * Returns the first selection range in the current document, by document position.
  3. * @return the first selection range in the current document, by document position
  4. */
  5. private Range getFirstRange() {
  6. // avoid concurrent modification exception
  7. final List<Range> ranges = new ArrayList<>(getRanges());
  8. Range first = null;
  9. for (final Range range : ranges) {
  10. if (first == null) {
  11. first = range;
  12. }
  13. else {
  14. final org.w3c.dom.Node firstStart = first.getStartContainer();
  15. final org.w3c.dom.Node rangeStart = range.getStartContainer();
  16. if ((firstStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
  17. first = range;
  18. }
  19. }
  20. }
  21. return first;
  22. }

代码示例来源:origin: HtmlUnit/htmlunit

  1. /**
  2. * Returns the last selection range in the current document, by document position.
  3. * @return the last selection range in the current document, by document position
  4. */
  5. private Range getLastRange() {
  6. // avoid concurrent modification exception
  7. final List<Range> ranges = new ArrayList<>(getRanges());
  8. Range last = null;
  9. for (final Range range : ranges) {
  10. if (last == null) {
  11. last = range;
  12. }
  13. else {
  14. final org.w3c.dom.Node lastStart = last.getStartContainer();
  15. final org.w3c.dom.Node rangeStart = range.getStartContainer();
  16. if ((lastStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_FOLLOWING) != 0) {
  17. last = range;
  18. }
  19. }
  20. }
  21. return last;
  22. }

代码示例来源:origin: com.rackspace.eclipse.webtools.sourceediting/org.eclipse.wst.xml.xpath2.processor

  1. private static int compare_node(NodeType a, NodeType b) {
  2. Node nodeA = a.node_value();
  3. Node nodeB = b.node_value();
  4. if (nodeA == nodeB || nodeA.isSameNode(nodeB)) return 0;
  5. Document docA = getDocument(nodeA);
  6. Document docB = getDocument(nodeB);
  7. if (docA != docB && ! docA.isSameNode(docB)) {
  8. return compareDocuments(docA, docB);
  9. }
  10. short relation = nodeA.compareDocumentPosition(nodeB);
  11. if ((relation & Node.DOCUMENT_POSITION_PRECEDING) != 0)
  12. return 1;
  13. if ((relation & Node.DOCUMENT_POSITION_FOLLOWING) != 0)
  14. return -1;
  15. throw new RuntimeException("Unexpected result from node comparison: " + relation);
  16. }

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

  1. /**
  2. * Runs the test case.
  3. * @throws Throwable Any uncaught exception causes test to fail
  4. */
  5. public void runTest() throws Throwable {
  6. Document doc;
  7. DocumentFragment docFrag;
  8. Element docElem;
  9. Attr attr;
  10. Node docFragChild;
  11. int attrPosition;
  12. int docFragChildPosition;
  13. Node appendedChild;
  14. Node attrNode;
  15. doc = (Document) load("hc_staff", true);
  16. docElem = doc.getDocumentElement();
  17. docFrag = doc.createDocumentFragment();
  18. attr = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang");
  19. attrNode = docElem.setAttributeNodeNS(attr);
  20. appendedChild = docFrag.appendChild(docElem);
  21. docFragChild = docFrag.getFirstChild();
  22. docFragChildPosition = (int) docFragChild.compareDocumentPosition(attr);
  23. assertEquals("nodecomparedocumentpositionIsContainedFollows15", 20, docFragChildPosition);
  24. attrPosition = (int) attr.compareDocumentPosition(docFragChild);
  25. assertEquals("nodecomparedocumentpositionPRECEEDINGContains15", 10, attrPosition);
  26. }
  27. /**

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

  1. return false;
  2. final short startComparison = start.compareDocumentPosition(otherStart);
  3. final boolean startNodeBefore = startComparison == 0
  4. || (startComparison & Node.DOCUMENT_POSITION_CONTAINS) != 0
  5. final org.w3c.dom.Node end = range_.getEndContainer();
  6. final org.w3c.dom.Node otherEnd = otherRange.getEndContainer();
  7. final short endComparison = end.compareDocumentPosition(otherEnd);
  8. final boolean endNodeAfter = endComparison == 0
  9. || (endComparison & Node.DOCUMENT_POSITION_CONTAINS) != 0

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

  1. /**
  2. * Runs the test case.
  3. * @throws Throwable Any uncaught exception causes test to fail
  4. */
  5. public void runTest() throws Throwable {
  6. Document doc;
  7. DocumentFragment docFrag;
  8. Element docElem;
  9. Node docFragChild;
  10. int docFragPosition;
  11. int docFragChildPosition;
  12. Node appendedChild;
  13. doc = (Document) load("hc_staff", true);
  14. docElem = doc.getDocumentElement();
  15. docFrag = doc.createDocumentFragment();
  16. appendedChild = docFrag.appendChild(docElem);
  17. docFragChild = docFrag.getFirstChild();
  18. docFragPosition = (int) docFrag.compareDocumentPosition(docFragChild);
  19. assertEquals("nodecomparedocumentpositionContainsPRECEDING14", 20, docFragPosition);
  20. docFragChildPosition = (int) docFragChild.compareDocumentPosition(docFrag);
  21. assertEquals("nodecomparedocumentpositionIsContainedFollowing14", 10, docFragChildPosition);
  22. }
  23. /**

相关文章