commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laird J. Nelson" <>
Subject [JXPath] Post-processing a node set?
Date Thu, 05 Jun 2003 22:29:38 GMT
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 =

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"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


View raw message