commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Hughes <ahhug...@gmail.com>
Subject Re: [JXPath] Iterators and Pointers (on partial matches)
Date Fri, 05 Jun 2009 00:25:27 GMT
Hi Matt,
Your explanation re: HierarchyTable sounds very similar. Another possible
option is if I can somehow tokenize the "steps" in the expression itself.
Then I could keep appending the .next() token... and re-run the expression
until it fails (in actual fact it would be best to start removing '--'
tokens from the end and re-querying as it is more responsive).

Somthing that would look like...

Iterator<String> tokens =
MythicalTokenizer.tokenize("/Earth/Australia/NSW/Sydney/Utopia");
jxpathContext.selectNode(expression+=tokens.next()); // success with
expression = "/Earth"
jxpathContext.selectNode(expression+=tokens.next()); // success with
expression = "/Earth/Australia"
jxpathContext.selectNode(expression+=tokens.next()); // success with
expression = "/Earth/Australia/NSW"
jxpathContext.selectNode(expression+=tokens.next()); // success with
expression = "/Earth/Australia/NSW/Sydney"
jxpathContext.selectNode(expression+=tokens.next()); // FAILURE with
expression = "/Earth/Australia/NSW/Sydney/Utopia"


I've had a look at the compiled expressions and parser's on the RI but I
can't see anything that would allow me to do this :'(   Hopefully I am
missing something.

THANKS HEAPS FOR THE RESPONSE!!!!
--Andrew


On Fri, Jun 5, 2009 at 12:03 AM, Matt Benson <gudnabrsam@yahoo.com> wrote:

>
> Hi Andrew,
>  I'm not sure if JXPath is necessarily really the right tool for this.
>  This almost just looks like a sort of hierarchical lookup.  I have a
> HierarchyTable we use at my $work for these type purposes; unfortunately I
> haven't yet gotten clearance to release it into the wild.  I plan someday to
> include it in [collections] but it may need rewriting before the Commons
> community would even agree to it, the reason being that it's somewhat heavy.
>  I suppose I can explain its implementation:  It stores hierarchical data a
> node per level, and its nodes it uses each hold a HashMap (the heavy part)
> to keep track of child nodes.  So you _could_ implement your own version of
> that.  If you are determined to use JXPath for this, for example if you just
> really need to be able to get at this information with an expression, you
> might be able to accomplish it with a custom function but I'm still afraid
> at some point you might have to parse the steps, or rely on JXPath RI
>  packages/classes.
>
> HTH,
> Matt
>
> --- On Wed, 6/3/09, Andrew Hughes <ahhughes@gmail.com> wrote:
>
> > From: Andrew Hughes <ahhughes@gmail.com>
> > Subject: [JXPath] Iterators and Pointers (on partial matches)
> > To: "Commons Users List" <user@commons.apache.org>
> > Date: Wednesday, June 3, 2009, 9:45 PM
> > 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)  :)
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message