1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jaxen.XPath;
import org.jaxen.XPathSyntaxException;
import org.jaxen.JaxenException;
import org.jaxen.jdom.JDOMXPath;
import java.io.File;
import java.util.List;
import java.util.Iterator;
public class JDOMDemo
{
public static void main(String[] args)
{
try
{
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("cave.xml");
System.out.println("doc "+doc.getBaseURI());
XPath xpath = new JDOMXPath("/CAVE/APPELATION/NOM_APPELATION/*[position()!=1]");
List results = xpath.selectNodes( doc );
Iterator resultIter = results.iterator();
System.out.println("Document :: " + "cave.xml" );
System.out.println(" XPath :: " + "/CAVE/APPELATION/*[position()!=1]" );
System.out.println("");
System.out.println("Results" );
System.out.println("----------------------------------");
while ( resultIter.hasNext() )
{
System.out.println( resultIter.next() );
}
}
catch (JDOMException e)
{
e.printStackTrace();
System.out.println("err "+e);
}
catch (XPathSyntaxException e)
{
System.err.println( e.getMultilineMessage() );
System.out.println("err "+e);
}
catch (JaxenException e)
{
e.printStackTrace();
System.out.println("err "+e);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("err "+e);
}
}
} |
Partager