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

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

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

Node.isSameNode介绍

[英]Returns whether this node is the same node as the given one.
This method provides a way to determine whether two Node references returned by the implementation reference the same object. When two Node references are references to the same object, even if through a proxy, the references may be used completely interchangeably, such that all attributes have the same values and calling the same DOM method on either reference always has exactly the same effect.
[中]返回此节点是否与给定节点相同。
此方法提供了一种确定实现返回的两个Node引用是否引用同一对象的方法。当两个Node引用是对同一对象的引用时,即使通过代理,这些引用也可以完全互换使用,这样所有属性都具有相同的值,并且对任一引用调用相同的DOM方法始终具有完全相同的效果。

代码示例

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

  1. @Override
  2. public boolean isSameNode(org.w3c.dom.Node other) {
  3. return node.isSameNode(other);
  4. }

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

  1. @Override
  2. public int compare(Node arg0, Node arg1) {
  3. int response = -1;
  4. if (arg0.isSameNode(arg1)) {
  5. response = 0;
  6. }
  7. //determine if the element is an ancestor
  8. if (response != 0) {
  9. boolean eof = false;
  10. Node parentNode = arg0;
  11. while (!eof) {
  12. parentNode = parentNode.getParentNode();
  13. if (parentNode == null) {
  14. eof = true;
  15. } else if (arg1.isSameNode(parentNode)) {
  16. response = 0;
  17. eof = true;
  18. }
  19. }
  20. }
  21. return response;
  22. }
  23. };

代码示例来源:origin: nutzam/nutz

  1. protected List<Element> getChildNodesByTagName(Element element, String tagName) {
  2. List<Element> list = new ArrayList<Element>();
  3. NodeList nList = element.getElementsByTagName(tagName);
  4. if(nList.getLength() > 0) {
  5. for (int i = 0; i < nList.getLength(); i++) {
  6. Node node = nList.item(i);
  7. if(node.getParentNode().isSameNode(element) && node instanceof Element)
  8. list.add((Element) node);
  9. }
  10. }
  11. return list;
  12. }
  13. }

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

  1. /**
  2. * Returns true if <code>m</code> is the same node <code>n</code>.
  3. */
  4. private boolean isSameNode(Node m, Node n) {
  5. return (fUseIsSameNode) ? m.isSameNode(n) : m == n;
  6. }
  7. }

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

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

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

  1. public boolean isSameNode(Node other)
  2. {
  3. return this.domNode.isSameNode(other);
  4. }

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

  1. @Override
  2. public boolean isSameNode(Node other) {
  3. return node.isSameNode(other);
  4. }

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

  1. public final boolean isSameNode(org.w3c.dom.Node other) {
  2. return target.isSameNode(other);
  3. }

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

  1. public final boolean isSameNode(org.w3c.dom.Node other) {
  2. return target.isSameNode(other);
  3. }

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

  1. protected List<Element> getChildNodesByTagName(Element element, String tagName) {
  2. List<Element> list = new ArrayList<Element>();
  3. NodeList nList = element.getElementsByTagName(tagName);
  4. if(nList.getLength() > 0) {
  5. for (int i = 0; i < nList.getLength(); i++) {
  6. Node node = nList.item(i);
  7. if(node.getParentNode().isSameNode(element) && node instanceof Element)
  8. list.add((Element) node);
  9. }
  10. }
  11. return list;
  12. }
  13. }

代码示例来源:origin: org.apache.ws.security/wss4j

  1. /**
  2. * Does the current element or some ancestor of it correspond to the known "signedElement"?
  3. */
  4. private static boolean isElementOrAncestorSigned(Element elem, Element signedElement)
  5. throws WSSecurityException {
  6. final Element envelope = elem.getOwnerDocument().getDocumentElement();
  7. Node cur = elem;
  8. while (!cur.isSameNode(envelope)) {
  9. if (cur.getNodeType() == Node.ELEMENT_NODE && cur.equals(signedElement)) {
  10. return true;
  11. }
  12. cur = cur.getParentNode();
  13. }
  14. return false;
  15. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.wss4j

  1. /**
  2. * Does the current element or some ancestor of it correspond to the known "signedElement"?
  3. */
  4. private static boolean isElementOrAncestorSigned(Element elem, Element signedElement)
  5. throws WSSecurityException {
  6. final Element envelope = elem.getOwnerDocument().getDocumentElement();
  7. Node cur = elem;
  8. while (!cur.isSameNode(envelope)) {
  9. if (cur.getNodeType() == Node.ELEMENT_NODE && cur.equals(signedElement)) {
  10. return true;
  11. }
  12. cur = cur.getParentNode();
  13. }
  14. return false;
  15. }

代码示例来源:origin: org.apache.wss4j/wss4j-ws-security-dom

  1. /**
  2. * Does the current element or some ancestor of it correspond to the known "signedElement"?
  3. */
  4. private static boolean isElementOrAncestorSigned(Element elem, Element signedElement)
  5. throws WSSecurityException {
  6. final Element envelope = elem.getOwnerDocument().getDocumentElement();
  7. Node cur = elem;
  8. while (!cur.isSameNode(envelope)) {
  9. if (cur.getNodeType() == Node.ELEMENT_NODE && cur.equals(signedElement)) {
  10. return true;
  11. }
  12. cur = cur.getParentNode();
  13. }
  14. return false;
  15. }

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

  1. public boolean isSameNode(DOMNode other)
  2. {
  3. return _delegate.isSameNode(other.getDelegate());
  4. }

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

  1. public static boolean same(NodeType a, NodeType b) {
  2. return (a.node_value().isSameNode(b.node_value()));
  3. // While compare_node(a, b) == 0 is tempting, it is also expensive
  4. }

代码示例来源: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: com.rackspace.eclipse.webtools.sourceediting/org.eclipse.wst.xml.xpath2.processor

  1. /**
  2. * returns parent accessors of the context node
  3. *
  4. * @param node
  5. * is the node type.
  6. * @throws dc
  7. * is the Dynamic context.
  8. */
  9. public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
  10. Node n = node.node_value();
  11. if (limitNode != null && limitNode.isSameNode(n)) {
  12. // no further, we have reached the limit node
  13. return;
  14. }
  15. Node parent = findParent(n);
  16. // if a parent exists... add it
  17. if (parent != null) {
  18. NodeType nodeType = NodeType.dom_to_xpath(parent, node.getTypeModel());
  19. if(nodeType != null) {
  20. copyInto.add(nodeType);
  21. }
  22. }
  23. }

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

  1. /**
  2. * Get the ancestors of the context node.
  3. *
  4. * @param node
  5. * is the type of node.
  6. */
  7. // XXX unify this with descendants axis ?
  8. public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
  9. if (limitNode != null && limitNode.isSameNode(node.node_value())) return;
  10. int before = copyInto.size();
  11. // get the parent
  12. super.iterate(node, copyInto, limitNode);
  13. // no parent
  14. if (copyInto.size() == before)
  15. return;
  16. NodeType parent = (NodeType) copyInto.item(before);
  17. // get ancestors of parent
  18. iterate(parent, copyInto, limitNode);
  19. }

代码示例来源:origin: org.opengis.cite.saxon/saxon9

  1. /**
  2. * Determine whether this is the same node as another node. <br />
  3. * Note: a.isSameNodeInfo(b) if and only if generateId(a)==generateId(b)
  4. * @return true if this Node object and the supplied Node object represent the
  5. * same node in the tree.
  6. */
  7. public boolean isSameNodeInfo(NodeInfo other) {
  8. if (!(other instanceof NodeWrapper)) {
  9. return false;
  10. }
  11. if (docWrapper.domLevel3) {
  12. return node.isSameNode(((NodeWrapper)other).node);
  13. } else {
  14. NodeWrapper ow = (NodeWrapper)other;
  15. return getNodeKind()==ow.getNodeKind() &&
  16. getNameCode()==ow.getNameCode() && // redundant, but gives a quick exit
  17. getSiblingPosition()==ow.getSiblingPosition() &&
  18. getParent().isSameNodeInfo(ow.getParent());
  19. }
  20. }

代码示例来源:origin: net.sf.saxon/Saxon-HE

  1. /**
  2. * Determine whether this is the same node as another node.
  3. * <p>Note: a.equals(b) if and only if generateId(a)==generateId(b)</p>
  4. *
  5. * @return true if this Node object and the supplied Node object represent the
  6. * same node in the tree.
  7. */
  8. public boolean equals(Object other) {
  9. if (!(other instanceof DOMNodeWrapper)) {
  10. return false;
  11. }
  12. if (docWrapper.domLevel3) {
  13. synchronized (docWrapper.docNode) {
  14. return node.isSameNode(((DOMNodeWrapper) other).node);
  15. }
  16. } else {
  17. DOMNodeWrapper ow = (DOMNodeWrapper) other;
  18. return getNodeKind() == ow.getNodeKind() &&
  19. equalOrNull(getLocalPart(), ow.getLocalPart()) && // redundant, but gives a quick exit
  20. getSiblingPosition() == ow.getSiblingPosition() &&
  21. getParent().equals(ow.getParent());
  22. }
  23. }

相关文章