You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Dmitri Plotnikov <dm...@plotnix.com> on 2001/09/03 03:45:08 UTC

[JXPath] support for DOM and transparent containers

I checked in two important additions to JXPath.

1. JXPath now supports DOM Nodes in addition to JavaBeans, objects with
Dynamic Properties and collections.  The DOM object can be the context node
of JXPathContext or it can be a value of a property, element of a
collection, variable value etc.  Let's say we have a path "$foo/bar/baz". It
will work just fine if the value of the variable "foo" is a JavaBean, whose
property "bar" is a DOM Node, which has a child element named "baz".   The
intepretation of XPath over DOM structures is implemented in strict
accordance with the XPath specification (at least I did my best). For
instance, the "attribute" axis is supported for DOM objects, even though it
is not applicable to JavaBeans.

I believe the addition of DOM support brings a certain closure to the whole
idea of using the XPath language to traverse Java object graphs.

2. JXPath now also supports "transparent containers".  Such a Container is
an object with the getValue() and setValue() methods.  A container is
traversed by JXPath transparently.  In the example above, the property "bar"
could be a Container that returns a DOM Node for getValue().  I implemented
a sample Container, XMLDocumentContainer, which is initialized with a URL or
a transformer Source. The first time the getValue() method is called, it
loads and parses an XML file.  JXPath than transparently walks into the DOM
tree for that file.

This feature can be used can be used when you need to occasionally access
some reference files. You simply wrap them into XMLDocumentContainers and
then use XPaths to access their elements. This way you can avoid unnecessary
parsing.

- Dmitri