1 9 10 package test.dom4j.xpath; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.Node; 16 import org.dom4j.io.SAXReader; 17 import test.dom4j.AbstractTestCase; 18 19 import java.io.File ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 28 public class TestSortBy extends AbstractTestCase { 29 30 protected static boolean VERBOSE = true; 31 32 33 public static void main( String [] args ) { 34 TestRunner.run( suite() ); 35 } 36 37 public static Test suite() { 38 return new TestSuite( TestSortBy.class ); 39 } 40 41 public TestSortBy(String name) { 42 super(name); 43 } 44 45 public void testXPaths() throws Exception { 48 49 List list = document.selectNodes( "//SPEAKER", "NAME" ); 50 51 log( "Number of SPEAKER instances: " + list.size() ); 52 53 List noDuplicates = document.selectNodes( "//SPEAKER", ".", true ); 54 55 log( "Number of distinct SPEAKER instances: " + noDuplicates.size() ); 56 57 log( "Number of distinct SPEAKER instances: " + noDuplicates.size() ); 58 59 if ( VERBOSE ) { 60 log( "Results of sorted XPath expression with duplicates removed... " ); 61 62 for ( Iterator iter = noDuplicates.iterator(); iter.hasNext(); ) { 63 Node node = (Node) iter.next(); 64 System.out.println( node.asXML() ); 65 } 66 } 67 } 68 69 protected void setUp() throws Exception { 70 document = new SAXReader().read( new File ( "xml/much_ado.xml" ) ); 71 } 72 } 73 74 75 76 77 121 | Popular Tags |