If two dom elements are equal in java

Is there a way to check if two dom elements are the same in Java?

What is the best way to test equality between two elements in JUnit Testing. If there is a java method for checking equality between two dom elements, then perhaps I could use assertTrue on this java method. Will this work?

Let's say I have two dom nodes, n1 and n2. I tried the following in a junit test:

assertTrue(n1.isEqualNode(n2));

Please see the results of my test print statements.

node n1 is: <?xml version="1.0" encoding="UTF-8"?><user trust="false"><userid>user</userid><password>70A0C520F974F76D994779C92326BEFFDECC344B</password><username>sony</username><organization>org</organization></user>

node n2 is: <?xml version="1.0" encoding="UTF-8"?><user trust="false">
  <userid>user</userid>
  <password>70A0C520F974F76D994779C92326BEFFDECC344B</password>
  <username>sony</username>
  <organization>org</organization>
</user>

This causes a Java approval error.

The nodes I used are exact replicas of each other with the same child node lists and values.

Thanks Sony

+3
source share
2
+2

java-: public boolean isEqualNode(Node arg);

, . , ( , ), Node.isSameNode(). , , .

IDE , n1 n2 n1.isEqualNode(n2).

node, public boolean isSameNode(Node other);.

+1

Source: https://habr.com/ru/post/1781172/


All Articles