First, I am a newbie.
I am getting an error while trying to use xpath and jdom. Here is the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/saxpath/SAXPathEx
ception
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at org.jdom.xpath.XPath.newInstance(XPath.java:133)
at hello.main(hello.java:26)
Here is my code:
import java.io.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.xpath.*;
import java.util.*;
public class hello
{
public static void main( String args[] ) throws Exception {
System.out.println("Hello") ;
System.out.println("Hello ugh") ;
Document doc = new SAXBuilder().build("catalog.xml");
List compositions = doc.getRootElement().getChildren("composition");
for(int i=0; i < compositions.size(); i++) {
String title = ((Element)compositions.get(i)).getChildText("title");
//here i want to get the composer, will use xpath to find it
//this line gets the 'key'
String comp = ((Element)compositions.get(i)).getAttribute("composer").getValue();
//this one does the xpath lookup
XPath xpath = XPath.newInstance("composer");
//List results = xpath.selectNodes(doc);
System.out.println(" " + title + " -- " + comp );
}
System.out.println("Done:");
}
}
Thanks,
LNMEgo