Hi, I believe I discovered a problem with the DefaultXPath.sort() methods and how the comparator works. I was attempting to sort by the numeric value of an attribute (versus the character/string value). By way of example, consider the following two XPath expressions: (1) "number(@id)" (2) "@id".
I would expect (1) to sort as follows: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 And I would expect (2) to sort as follows: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9 However, both of them sorted as follows: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9 Looking at the org.dom4j.xpath.DefaultXPath.java implementation, I believe the issue is that the getCompareValue(Node node) method is implemented by calling the valueOf method on the xpath expression. However, the valueOf method always returns the string value of the XPath expression. I believe it should be implemented as follows: /** @return the node expression used for sorting comparisons */ protected Object getCompareValue(Node node) { return selectObject( node ); } The selectObject method returns the java.lang.Number implementation when the number() XPath function is used. I made these changes and the sort now works like I would expect it to. I found a post by James Strachan where he indicated he thought it should work this way but he had not written the test cases. However, I noticed that both selectObject and valueOf were deprecated. So now I'm wondering - 1) Is this a legitimate problem? Or am I doing to something wrong here? 1) should I submit a patch for this? what's the plan around the deprecated methods? DAn ------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ dom4j-dev mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-dev