The reason is that dom4j nodes use identity based equality: 2 nodes are equal if they reference the same object instance. In your case: the documents are different objects, so the nodes will be different objects too and the equals() method will always return false.

To solve your problem: you could iterate the 2 lists manually and use org.dom4j.util.NodeComparator to compare the nodes:

if (listNodesOriginal.size() != listNodesNew.size()) {
   return false;
} else {
   NodeComparator comparator = new NodeComparator();
   for (int i = 0; i < listNodesOriginal.size(); i++) {
       Node orig = (Node) listNodesOriginal.get(i);
       Node newNode = (Node) listNodesNew.get(i);
       if (comparator.compare(orig, newNode) != 0) {
            return false;
       }
   }
   return true;
}

regards,
Maarten

Z Z wrote:

Hello ,

I need to compare two XPath results Lists on different document.

this is how i do that now, why doen't it work ?

( i want to compare the lists returns by XPath by value and not by
references to the nodes - deeo compare)

here is my code :

   List listNodesOriginal = m_leftDocument.selectNodes(m_strXPathLeft);
   List listNodesNew = newLeftDocument.selectNodes(m_strXPathLeft);

   if ( listNodesOriginal.equals(listNodesNew))
       return false;
   else
       return true;

m_leftDocument and newLeftDocument have been read from different xml files.
( no common references to same nodes)
my code, always returns false,
althought for some XPath expressions i need it to return true,


please help.
thank you.
Grosman

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to