commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dplot...@yahoo.com>
Subject Re: [JXPath] Post-processing a node set?
Date Fri, 06 Jun 2003 14:07:20 GMT
Sure, JXPath can handle that.  You will need to write extension
functions that perform the postprocessing.  See
http://jakarta.apache.org/commons/jxpath/users-guide.html#Extension%20Functions

On the other hand, have you considered using an XSLT preprocessor
instead?  XSLT appears to be better suited for the type of
transformation you are describing and will probably also perform
better.

- Dmitri


--- "Laird J. Nelson" <ljnelson94@alumni.amherst.edu> wrote:
> I'm working on a translator of sorts that I'd like to use JXPath
> internally for.  I'm first trying to determine whether JXPath can
> handle
> the requirements.
> 
> On the "right hand side" I have a graph of Castor-generated objects
> that
> come from a disgusting XML document with its data scattered all over
> hither and yon.  For reasons that are not important but are entirely
> inflexible, the structure of these objects cannot be changed by me or
> my
> team.  However, they can be changed at will by the folks whipping up
> the
> XML.  In practice, this means that element Q, which used to be a
> child
> of element R, is frequently yanked around so that where it appears in
> the document changes on a daily basis.  Consequently, the Castor
> object
> graph is large, unwieldy, our only interface to the data we need, and
> has a bunch of extra junk in it we don't even want to look at.
> 
> On the "left hand side" I have a beautiful, pristine object graph
> representing the state of an application I'm writing.  :-)
> 
> The idea I had was to feed in a set of dynamic rules consisting of
> two
> JXPath expressions separated by an equals sign, or something like
> that:
> 
>     /appModel/frobnicationInterval =
> /BigUglyDoc//BunchOfJunk//Frobnicator/@interval
> 
> Provided I've installed a variable named "appModel" into the
> JXPathContext and provided it indeed has a JavaBean
> "frobnicationInterval" property, and provided that the XML
> document/Castor graph has somewhere in its tree a <Frobnicator
> interval="12"> element, then JXPath, if I understand the docs and if
> I
> install the relevant factories, should set the frobnication interval
> on
> my app model properly from the gleaming nuggets of relevant, useful
> information buried in the giant Castor hairball, if I write the
> correct
> generic glue code to process configuration entries of this type.
> 
> So for simple primitives, this is great and will make my life easier.
> 
> But what about the case where the appModel has a property that takes
> a
> complex object, but the Castor object graph is only capable of
> returning
> that object's component parts?  Pretend the Castor graph can give me
> nodes representing x and y coordinates, but my app model requires a
> Point object.  Are there any JXPath tricks I can use
> to...to..."postprocess" a node set returned by an XPath expression
> before it's returned, e.g. to have the node set aggregated and
> otherwise
> munged into a collection of Point objects instead of a stream of x
> and y
> coordinates?
> 
> Cheers,
> Laird
> --
> ljnelson94@alumni.amherst.edu
> 
> 
> ---------------------------------------------------------------------
> 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! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

Mime
View raw message