[jdom-interest] XPath problem using org.jdom.xpath

Damien Conlon damien.conlon at eurokom.ie
Thu Mar 11 02:17:49 PST 2004


Hi,

Hopefully someone can point me in the right direction here - I'm trying to
use org.jdom.xpath.XPath to parse an XML file, and seem to have run into a
problem caused when trying to get an ancestor using an XPath expression:

Exception in thread "main" java.lang.NoSuchMethodError:
org.jdom.Element.getParent()Lorg/jdom/Element;
at
org.jaxen.jdom.DocumentNavigator.getParentAxisIterator(DocumentNavigator.jav
a:252)
at
org.jaxen.expr.iter.IterableParentAxis.iterator(IterableParentAxis.java:82)
at org.jaxen.expr.DefaultStep.axisIterator(DefaultStep.java:139)
at
org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:188)
at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:107)
at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:716)
at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:239)
at org.jdom.xpath.JaxenXPath.selectNodes(JaxenXPath.java:123)
at org.jdom.xpath.XPath.selectNodes(XPath.java:337)
at XPathReader.main(XPathReader.java:34)


The (very small) test class I'm running is a stripped-down version of
jdom-b10\samples\XPathReader.java and shown below:

import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.xpath.*;

public class XPathReader {

public static void main(String[] args) throws IOException, JDOMException {
if (args.length != 1) {
System.err.println("Usage: XPathReader [web.xml]");
return;
}
String filename = args[0];

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File(filename));

// Print servlet information
XPath servletPath = XPath.newInstance("//servlet");
Element servlet = (Element)servletPath.selectSingleNode(doc);

List ancestors = (ArrayList)XPath.selectNodes(servlet,".");
System.out.println(ancestors);
}
}




My classpath includes only the following:

.
jdom-b10\build\jdom.jar
jdom-b10\lib\saxpath.jar
jdom-b10\lib\jaxen-jdom.jar
jdom-b10\lib\jaxen-core.jar


The funny thing is that the NoSuchMethodError related to
org.jdom.Element.getParent() disappears if we change the second last line of
XPathReader to:

List ancestors = (ArrayList)XPath.selectNodes(servlet,"*");

(i.e. trying to get the children instead of the ancestors)

Is this a problem in jdom or jaxen? Or am I overlooking something?

-Damien Conlon




More information about the jdom-interest mailing list