Hi Tilman,
I think there's real potential for doing what you're talking about using
JiBX and XPath. The JiBX binding already creates a mapping between Java
objects and XML, so the binding can be used to map XPath queries into
the corresponding Java objects. Doing this at runtime for arbitrary
XPath expressions would be messy, since that's not how JiBX is generally
intended to work with the binding, but there's no reason predefined
expressions couldn't be compiled directly into the code.
The JiBX 2.0 framework should provide a good basis for doing this. Most
of it could even be done using the current framework, since the binding
definition model code is not going through any major changes for 2.0,
but the 2.0 code generation is going to be substantially different
including using ASM rather than BCEL.
I haven't looked into XUpdate enough to say how easy it'd be to extend
this approach to include XUpdate support. If you can execute XPath
queries it seems like that should be a major part of the work, though.
- Dennis
TIlman Linden wrote:
Hi Eitan and all,
I was also thinking about integration of JiBX and XPath recently. I
was looking for a possibility to run XPath queries over Java object
trees (JOTs), which are "somehow" connected to XML data ("somehow"
means, that this could for example be described by a JiBX binding.)
While jaxen and JXPath claim to support this, in both cases I wasn't
satisfied with the exisiting techniques. The JXPath support for JOT
works, but the XPath expression for querying an object tree is not
necessarily equal to the expression for querying the according XML
document if you want to obtain equal results. Jaxen's support for JOT
seems not to be implemented completely, and there were some remarks on
the jaxen developer list about some problems which need to be solved
beforehand. One of these mentioned problems was that in JOTs a set of
the XPath axes is not clearly defined. This especially counts for the
"parent" axis, and all axes which are based on the document order,
like "descendant" and "ascendant" axes.
This is where a binding framework like JiBX comes into play, because a
binding as in JiBX exactly defines the axes missing in Java. With a
binding definition you always know the "document place" of a member in
a JOT. To run XPath on the JOT using the same expressions as if you
would query the XML document, you would not even need an attribute
"xpath='...'" like Eitan proposed (Or did I miss something in that idea?)
I am wondering about possible use cases of the discussed techniques.
In our current project we are using XUpdate (including XPath) for a
protocol to synchronize distributed instances of XML documents which
are represented in JOTs. Here we really need an integration of
(un)marshalling and XPath/XUpdate functionality for JOTs. We do not
use JiBX currently (because I wasn't the one to decide which data
binding framework to use :) but a combination of JDOM and handmade
code for (un)marshalling and a prototypical extension for jaxen to run
XPath/XUpdate over bound JOTs. While this works quite OK, the code is
rather blown up and the performance is of course weak (our
prototypical binding framework for XPath queries uses Java reflection
API).
Which use cases could other people on this list imagine? One could
argue, that when using XML techniques like XPath and XUpdate to access
your data, (un)marshalling to a customized JOT becomes obsolete. One
could also just use a common DOM implementation to represent your
data. (I think the article mentioned by Eitan points in this
direction.) Is there the common need for "native" Java access to data
(Object.getMemeber()) combined with XPath access (/node/@attribute) to
the same data?
Regards,
Tilman
Eitan Suez wrote:
hi all,
while on developerworks reading dennis' articles, i also
came across this one:
http://www-128.ibm.com/developerworks/java/library/x-pracdb8.html
entitled: 'xpath as a data binding tool, part 1'
i have to admit i just skimmed the article but it grabbed my
attention. i've been thinking for a while that adding
xpath to jibx would be a good move.
more specifically what i mean is that the jibx binding
vocabulary could be extended nicely with xpath support.
here's an example binding file:
<binding name="binding1">
<mapping name="customer" class="simple.Customer">
<structure field="name">
<value name="first-name" field="firstName"/>
<value name="last-name" field="lastName"/>
</structure>
<value name="street" field="street1"/>
<value name="city" field="city"/>
<value name="state" field="state"/>
<value name="zip" field="zip"/>
<value name="phone" field="phone"/>
</mapping>
</binding>
in jibx we use the attribute 'name' to bind a specific
element or attribute name to a java field. i think that could
be a perfect spot in the jibx binding file for introducing
an alternative to name="" : xpath=""
as in:
<value xpath="name/first-name" field="firstName" />
i know this is not a complete description of how such an
enhancement would work or fit in to jibx. but it's a starting
point for consideration, and definitely for discussion.
/ eitan
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users