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

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

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

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

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

@Override
  public int compare(Node arg0, Node arg1) {
    int response = -1;
    if (arg0.isSameNode(arg1)) {
      response = 0;
    }
    //determine if the element is an ancestor
    if (response != 0) {
      boolean eof = false;
      Node parentNode = arg0;
      while (!eof) {
        parentNode = parentNode.getParentNode();
        if (parentNode == null) {
          eof = true;
        } else if (arg1.isSameNode(parentNode)) {
          response = 0;
          eof = true;
        }
      }
    }
    return response;
  }
};

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

protected List<Element> getChildNodesByTagName(Element element, String tagName) {
    List<Element> list = new ArrayList<Element>();
    NodeList nList = element.getElementsByTagName(tagName);
    if(nList.getLength() > 0) {
      for (int i = 0; i < nList.getLength(); i++) {
        Node node = nList.item(i);
        if(node.getParentNode().isSameNode(element) && node instanceof Element)
          list.add((Element) node);
      }
    }
    return list;
  }
}

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

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

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

/**
 * @param other
 * @return
 * @see org.w3c.dom.Node#isSameNode(org.w3c.dom.Node)
 */
public boolean isSameNode(Node other) {
  return parent.isSameNode(other);
}

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

public boolean isSameNode(Node other)
{
 return this.domNode.isSameNode(other);
}

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

@Override
public boolean isSameNode(Node other) {
  return node.isSameNode(other);
}

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

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

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

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

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

protected List<Element> getChildNodesByTagName(Element element, String tagName) {
    List<Element> list = new ArrayList<Element>();
    NodeList nList = element.getElementsByTagName(tagName);
    if(nList.getLength() > 0) {
      for (int i = 0; i < nList.getLength(); i++) {
        Node node = nList.item(i);
        if(node.getParentNode().isSameNode(element) && node instanceof Element)
          list.add((Element) node);
      }
    }
    return list;
  }
}

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

/**
 * Does the current element or some ancestor of it correspond to the known "signedElement"? 
 */
private static boolean isElementOrAncestorSigned(Element elem, Element signedElement) 
  throws WSSecurityException {
  final Element envelope = elem.getOwnerDocument().getDocumentElement();
  Node cur = elem;
  while (!cur.isSameNode(envelope)) {
    if (cur.getNodeType() == Node.ELEMENT_NODE && cur.equals(signedElement)) {
      return true;
    }
    cur = cur.getParentNode();
  }
  
  return false;
}

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

/**
 * Does the current element or some ancestor of it correspond to the known "signedElement"? 
 */
private static boolean isElementOrAncestorSigned(Element elem, Element signedElement) 
  throws WSSecurityException {
  final Element envelope = elem.getOwnerDocument().getDocumentElement();
  Node cur = elem;
  while (!cur.isSameNode(envelope)) {
    if (cur.getNodeType() == Node.ELEMENT_NODE && cur.equals(signedElement)) {
      return true;
    }
    cur = cur.getParentNode();
  }
  
  return false;
}

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

/**
 * Does the current element or some ancestor of it correspond to the known "signedElement"?
 */
private static boolean isElementOrAncestorSigned(Element elem, Element signedElement)
  throws WSSecurityException {
  final Element envelope = elem.getOwnerDocument().getDocumentElement();
  Node cur = elem;
  while (!cur.isSameNode(envelope)) {
    if (cur.getNodeType() == Node.ELEMENT_NODE && cur.equals(signedElement)) {
      return true;
    }
    cur = cur.getParentNode();
  }
  return false;
}

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

public boolean isSameNode(DOMNode other)
{
 return _delegate.isSameNode(other.getDelegate());
}

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

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

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

private static int compare_node(NodeType a, NodeType b) {
  Node nodeA = a.node_value();
  Node nodeB = b.node_value();
  
  if (nodeA == nodeB || nodeA.isSameNode(nodeB)) return 0;
  Document docA = getDocument(nodeA);
  Document docB = getDocument(nodeB);
  
  if (docA != docB && ! docA.isSameNode(docB)) {
    return compareDocuments(docA, docB);
  }
  short relation = nodeA.compareDocumentPosition(nodeB);
  if ((relation & Node.DOCUMENT_POSITION_PRECEDING) != 0) 
     return 1;
  if ((relation & Node.DOCUMENT_POSITION_FOLLOWING) != 0) 
     return -1;
  throw new RuntimeException("Unexpected result from node comparison: " + relation);
}

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

/**
 * returns parent accessors of the context node
 * 
 * @param node
 *            is the node type.
 * @throws dc
 *             is the Dynamic context.
 */
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
  Node n = node.node_value();
  
  if (limitNode != null && limitNode.isSameNode(n)) {
    // no further, we have reached the limit node
    return;
  }
  Node parent = findParent(n);
  // if a parent exists... add it
  if (parent != null) {
    NodeType nodeType = NodeType.dom_to_xpath(parent, node.getTypeModel());
    if(nodeType != null) {
      copyInto.add(nodeType);
    }
  }
}

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

/**
 * Get the ancestors of the context node.
 * 
 * @param node
 *            is the type of node.
 */
// XXX unify this with descendants axis ?
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
  if (limitNode != null && limitNode.isSameNode(node.node_value())) return;
  
  int before = copyInto.size();
  // get the parent
  super.iterate(node, copyInto, limitNode);
  // no parent
  if (copyInto.size() == before)
    return;
  NodeType parent = (NodeType) copyInto.item(before);
  // get ancestors of parent
  iterate(parent, copyInto, limitNode);
}

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

/**
* Determine whether this is the same node as another node. <br />
* Note: a.isSameNodeInfo(b) if and only if generateId(a)==generateId(b)
* @return true if this Node object and the supplied Node object represent the
* same node in the tree.
*/
public boolean isSameNodeInfo(NodeInfo other) {
  if (!(other instanceof NodeWrapper)) {
    return false;
  }
  if (docWrapper.domLevel3) {
    return node.isSameNode(((NodeWrapper)other).node);
  } else {
    NodeWrapper ow = (NodeWrapper)other;
    return getNodeKind()==ow.getNodeKind() &&
      getNameCode()==ow.getNameCode() &&  // redundant, but gives a quick exit
      getSiblingPosition()==ow.getSiblingPosition() &&
      getParent().isSameNodeInfo(ow.getParent());
  }
}

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

/**
 * Determine whether this is the same node as another node.
 * <p>Note: a.equals(b) if and only if generateId(a)==generateId(b)</p>
 *
 * @return true if this Node object and the supplied Node object represent the
 *         same node in the tree.
 */
public boolean equals(Object other) {
  if (!(other instanceof DOMNodeWrapper)) {
    return false;
  }
  if (docWrapper.domLevel3) {
    synchronized (docWrapper.docNode) {
      return node.isSameNode(((DOMNodeWrapper) other).node);
    }
  } else {
    DOMNodeWrapper ow = (DOMNodeWrapper) other;
    return getNodeKind() == ow.getNodeKind() &&
        equalOrNull(getLocalPart(), ow.getLocalPart()) &&  // redundant, but gives a quick exit
        getSiblingPosition() == ow.getSiblingPosition() &&
        getParent().equals(ow.getParent());
  }
}

相关文章