Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[XML/XPath] jaxen : problem with XPath "parent" function

Status
Not open for further replies.

funxav

Programmer
Jun 13, 2003
15
FR
Hello

I have a problem with jaxen, when I try to use the XPath function parent :
When I try this :


Code:
import ...

DocumentNavigator dn=new DocumentNavigator();
try {
   objet=dn.getDocument("TESTXPath.xml");                   
        apath=dn.parseXPath("/Entry/Resultats/step/Population/individu/*");
        result=apath.evaluate(objet);
        System.out.println(result);
        apath=dn.parseXPath("/Entry/Resultats/step/Population/parent::*");
        result=apath.evaluate(objet); // ---> exception
        System.out.println(result);
}
catch(Exception e) {
  e.printStackTrace();
}

The first result is well displayed, but just before the second, I catch this exception:

Exception in thread "main" java.lang.NoSuchMethodError: org.jdom.Element.getParent()Lorg/jdom/Element; at org.jaxen.jdom.DocumentNavigator.getParentAxisIterator(DocumentNavigator.java: 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.DefaultAbsoluteLocationPath.evaluate(DefaultAbsoluteLocationPat h.java:126)
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.jaxen.BaseXPath.evaluate(BaseXPath.java:196)
at MainTestClass.main(MainTestClass.java:85)

However, the first query works good and I received list so I'm quite sure that it's not a problem of unfindable elements.

Finaly I can't be syccessful to use XPath parent function:
Either I catch an exception, or it returns nothing or empty list

Isn't the XPath syntax correct in my second expression ?
Can we do :
/.../.../parent::* ? ou //individu/parent::* ?
 
This exception :

Code:
Exception in thread "main" java.lang.NoSuchMethodError: org.jdom.Element.getParent()Lorg/jdom/Element

says that there is "no method that matches the required signature for the class org.jdom.Element". I would suspect you have either two version of jdom in your CLASSPATH, or an old version ...


--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks

I use jdom b10.
So perhaps I must use another version ?

I'm going to search if there is another more recent version...
 
I have tried to reset all JDOM (jaxen is in jdom) paths.

It doesn't work.
I have jdk1.4.2 and try jdom-b10

It's strange because all work excepted the call to XPATH "parent" function (child function and abreviated path works fine.)

So I 'm going to try with jdom-b9, but I'm not convinced ...^^
 
I have the same problem... Whenever I try to use a xpath function that needs parent(), it throws this exception...

ex: //metric/type[text() = 'Lines of Code'] works fine,
but
//metric/type[text() = 'Lines of Code']/next-sibling::value

throws the parent exception because internally, jdom uses parent() and probably position to find the next sibling... I reset all paths to jdom and jaxen, and I was using jdom9... Changed to 10 with no improvement...

Any more ideas ?
 
OOps, the second expression is not "next-sibling::value", but of course "following-sibling::value"... Sorry for the typo, even though I still have this problem to solve...
 
In fact I use now jdom.jar in jdom-b9.zip and its works. You can also use jdom.jar in lib rep of lastest download of jaxen.

I don't understand why but its works for me.
So, I hope it could help you ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top