commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dmi...@apache.org>
Subject Re: [JXPath] evaluating expression on a given node
Date Thu, 20 Feb 2003 05:25:00 GMT
Christian,

----- Original Message -----
From: "Christian Sell" <christian.sell@netcologne.de>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Wednesday, February 19, 2003 11:24 AM
Subject: Re: [JXPath] evaluating expression on a given node


> Dmitri Plotnikov wrote:
> > Christian,
> >
> > Let me see if I understand your requirement correctly.
> >
> > You are reading an XML stream and building a custom data tree.  After
> > you have built a node of the tree you need to check if it meets some
> > condition.  If this is in fact what you are doing, JXPath should work
> > fine for you.
>
> that sounds like a good descriptions of my problem, indeeed
>
> >
> > If the node is added to the tree before the condition is checked and
> > you know exactly where in the tree the new node is, you could get away
> > with one JXPathContext, e.g.:
> >
> >    Boolean success = (Boolean)context.
> >       getValue("string-length(/employees[4]/addresses[2]/zipCode) =
> > 5");
>
> that is not feasible, as I want to be able to evaluate for an arbitrary
> node inside the tree, and I cannot control the expression being provided.
Ok, I understand this.

> > Otherwise you would have to create a new JXPathContext for each node:
> >
> >    JXPathContext context = JXPathContext.newContext(node);
> >    Boolean success = (Boolean)context.
> >       getValue("string-length(street) <= 50");
> >
> > In the latter case, especially if you need custom extension functions,
> > you might want to create a reusable base context. See
> >
http://jakarta.apache.org/commons/jxpath/users-guide.html#Nested%20Contexts
>
> I am not getting this. Why would I create new contexts, and where would
> I keep them? What context do I hand the expression to?
You will need to create a separate context for every node, because a context
is associated with its context node at birth and for life.  You don't need
to keep the contexts - create them as you need them and throw them away.
They are really not heavy weight at all, provided that you keep all the
heavy-weight stuff like variables and extension functions on the shared base
context.

> Let me try to explain my issue once again:
>
> I have an expression that is provided externally (by the user), which
> states, for example "every 'book' node which has a 'category' child node
> containing the text 'fiction'  shall be colored in red". Now, while I am
> processing the XML document, I want to determine for each node whether
> it meets the condition.
>
> More conditions:
>
> - the data tree objects do not conform to the JavaBean spec. I have to
> use custom code to determine their properties
This might be an issue - you will need custom BeanInfos for them.

> - I dont want to parse the XML document or the XPath expression more
> than once.
To avoid recompiling XPaths, compile them as a separate step by calling
JXPathContext.compile(xpath) and cache the resulting CompiledExpressions.

I hope this helps.

> thanks,
> Christian

>
> BTW, any hints on how to build JXPath from cvs? I am getting lots of
> test failures, and maven.log is full of error messages about invalid
> uses of Jelly tags.
If you are having problems with the Maven build, try the regular Ant build -
it works like a charm.

- Dmitri


> > I hope this helps.
> >
> > - Dmitri

> >
> > --- Christian Sell <christian.sell@netcologne.de> wrote:
> >
> >>Hello,
> >>
> >>I am intending to use XPath from inside an SAX DefaultHandler by
> >>determining whether the current node conforms to a given expression.
> >>At
> >>this point I have the node tree available in an application-specific
> >>format which is built during parsing.
> >>
> >>at first glance it seems to me that to do this I would have to delve
> >>rather deep into the evaluation mechanism and adapt it to my purpose.
> >>
> >>Does anyone have hints that may help me towards my purpose? Is JXPath
> >>
> >>the right tool, or is there some other plaxe I should look to?
> >>
> >>TIA,
> >>Christian
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >
> >
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Shopping - Send Flowers for Valentine's Day
> > http://shopping.yahoo.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>


Mime
View raw message