Java XML Node Value Check isNodeTheSame(Node node1, Node node2)

Here you can find the source of isNodeTheSame(Node node1, Node node2)

Description

Use DTMNodeProxy to determine whether two nodes are the same.

License

Apache License

Parameter

Parameter Description
node1 The first DOM node to compare.
node2 The second DOM node to compare.

Return

true if the two nodes are the same.

Declaration

public static boolean isNodeTheSame(Node node1, Node node2) 

Method Source Code

//package com.java2s;
/*/*from   w w w .  j  av a2 s  .c  om*/
 * Copyright 1999-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;

import org.w3c.dom.Node;

public class Main {
    /**
     * Use DTMNodeProxy to determine whether two nodes are the same.
     * 
     * @param node1 The first DOM node to compare.
     * @param node2 The second DOM node to compare.
     * @return true if the two nodes are the same.
     */
    public static boolean isNodeTheSame(Node node1, Node node2) {
        if (node1 instanceof DTMNodeProxy && node2 instanceof DTMNodeProxy)
            return ((DTMNodeProxy) node1).equals((DTMNodeProxy) node2);
        else
            return (node1 == node2);
    }
}

Related

  1. isMixed(org.w3c.dom.Node node)
  2. isNamedElement(final Node aNode)
  3. isNode(Object value, String nodeName)
  4. isNodeAfter(Node node1, Node node2)
  5. isNodeNameEquals(Node node, String desiredName)
  6. isNodeTypeElement(Node node)
  7. isNullOrEmpty(Node node)
  8. isOrphanNode(Node node)
  9. isReturnTag(Node node)