first of all, thanks for this great piece of code - its a vital part of our own open-source project.
but i have a problem using the last() function in jxpath. i'm using the following xml:
<instance>
<my:order my:money="4711">
<my:item my:money="50">
<my:amount>500</my:amount>
<my:discount>100</my:discount>
</my:item>
<my:item my:money="4711">
<my:amount>77</my:amount>
<my:discount>77</my:discount>
</my:item>
</my:order>
</instance>i'm trying to get the last element of a nodeset like this:
JXPathContext context = JXPathContext.newContext(doc);
Pointer pointer1 = context.getPointer("//my:order/my:item[2]");
assertTrue(pointer1.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));works ok.
Pointer pointer2
=context.getPointer("//my:order/my:item[position()=count(../*)]");
assertTrue(pointer2.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));works ok.
Pointer pointer3 =
context.getPointer("//my:order/my:item[position()=2]");
assertTrue(pointer3.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));works ok.
Pointer pointer4 = context.getPointer("//my:order/my:item[last()]");
assertTrue(pointer4.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));fails with stacktrace. what am i doing wrong? please help. i've investigated the problem but cannot find a way to get it working.
any help appreaciated.
Joern
testLast(org.chiba.xml.xforms.xpath.test.JXPathTest)java.lang.NullPointerException
at org.apache.commons.jxpath.ri.model.dom.DOMNodeIterator.previous(DOMNodeIterator.java:131)
at org.apache.commons.jxpath.ri.model.dom.DOMNodeIterator.setPosition(DOMNodeIterator.java:121)
at org.apache.commons.jxpath.ri.axes.ChildContext.setPosition(ChildContext.java:152)
at org.apache.commons.jxpath.ri.compiler.CoreFunction.functionLast(CoreFunction.java:335)
at org.apache.commons.jxpath.ri.compiler.CoreFunction.computeValue(CoreFunction.java:259)
at org.apache.commons.jxpath.ri.axes.PredicateContext.nextNode(PredicateContext.java:127)
at org.apache.commons.jxpath.ri.EvalContext.getSingleNodePointer(EvalContext.java:333)
at org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:211)
at org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path.java:192)
at org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath.java:128)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer(JXPathContextReferenceImpl.java:366)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer(JXPathContextReferenceImpl.java:362)
at org.chiba.xml.xforms.xpath.test.JXPathTest.testLast(JXPathTest.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
