1 61 62 63 import org.jdom.Document; 64 import org.jdom.JDOMException; 65 import org.jdom.input.SAXBuilder; 66 67 import org.jaxen.XPath; 68 import org.jaxen.XPathSyntaxException; 69 import org.jaxen.JaxenException; 70 71 import org.jaxen.jdom.JDOMXPath; 72 73 import java.util.List ; 74 import java.util.Iterator ; 75 76 public class JDOMDemo 77 { 78 public static void main(String [] args) 79 { 80 if ( args.length != 2 ) 81 { 82 System.err.println("usage: JDOMDemo <document url> <xpath expr>"); 83 System.exit( 1 ); 84 } 85 86 try 87 { 88 SAXBuilder builder = new SAXBuilder(); 89 90 Document doc = builder.build( args[0] ); 91 92 XPath xpath = new JDOMXPath( args[1] ); 93 94 List results = xpath.selectNodes( doc ); 95 96 Iterator resultIter = results.iterator(); 97 98 System.out.println("Document :: " + args[0] ); 99 System.out.println(" XPath :: " + args[1] ); 100 System.out.println(""); 101 System.out.println("Results" ); 102 System.out.println("----------------------------------"); 103 104 while ( resultIter.hasNext() ) 105 { 106 System.out.println( resultIter.next() ); 107 } 108 } 109 catch (JDOMException e) 110 { 111 e.printStackTrace(); 112 } 113 catch (XPathSyntaxException e) 114 { 115 System.err.println( e.getMultilineMessage() ); 116 } 117 catch (JaxenException e) 118 { 119 e.printStackTrace(); 120 } 121 catch (Exception e) 122 { 123 e.printStackTrace(); 124 } 125 } 126 } 127 | Popular Tags |