You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Andrew Hughes <ah...@gmail.com> on 2009/06/04 04:45:59 UTC

[JXPath] Iterators and Pointers (on partial matches)

Hi Again,
I'm trying to resolve an issue I have trying to step through object's
slightly *different* to the JXPath ReferenceImpl.

Say I have String expression = "/Earth/Australia/NSW/Sydney/Utopia"; Since
"Utopia" is a mythical place that never exists I'll never get a result from
selectNode("/Earth/Australia/NSW/Sydney/Utopia");

Neither can I do this with an iterator:
http://commons.apache.org/jxpath/apidocs/org/apache/commons/jxpath/JXPathContext.html#iteratePointers(java.lang.String)

"If the xpath matches no properties in the graph, the Iterator be empty, but
not null."

I've tested this is and when I look for Utopia, I get an empty iterator....

I need an iterator that allows me see just how close I can get to 'Utopia':

Iterator step = jxpathContext.iterator("/Earth/Australia/NSW/Sydney/Utopia"
);
system.out.println(step.next().toString());// '' the root object
system.out.println(step.next().toString());// 'Earth'
system.out.println(step.next().toString());// 'Australia'
system.out.println(step.next().toString());// 'NSW'
system.out.println(step.next().toString());// 'Sydney'
system.out.println(step.next().toString());// THROWS AN EXCEPTION BECAUSE
UTOPIA DOES NOT EXIST!!!!


Thanks heaps for reading (again)  :)