[jdom-interest] XPath

Yoichi Takayama yoichi at webmcq.com
Thu May 24 17:10:24 PDT 2001

Dear Bob,

I tried Werken XPath and I know that it gives me back the Object I want 
from the JDOM tree when I give it an XPath expression.

Is there a class to do something a bit like reverse, like, construct a 
whole tree for me when I give a bunch of XPath/value pairs?

It is a bit like marshaling/unmarshaling, I suppose, but the results is 
written out like Xpath/value pairs and back.


         <title>First page</title>
         <title>Second Page</title>

Write out as:

/doc/page[0]/title[text()]:=First Page
/doc/page[1]/title[text()]:=Second Page

Then back, using above text output as input

create doc with no content and no attribute
create page and put it as a child of doc
create title for page[0] and create text and put it as a child of page[0]
create page[1] and put it as a child of doc
create title for page[1] and create text and put it as a child of page[1]
return the doc JDOM tree

N.B. the order which the XPath are given should not be significant
i.e. if only /doc/page[1]/title[text()]:=Second Page is given, the whole 
tree must be constructed to reach to that item, i.e. an empty page[0] must 
be created.  Therefore, the XPath always is an absolute path not a relative 
and nested one (though nested usage can be OK in some applications).

This may look like a silly and trivial exercise for you and sure I can 
write something to do it, but I wonder if someone else has done something 
similar already with full implementation of XPath specs.

I have a use for this kind of code for HTML form processing.  Is there a 
better way???  Of course, the alternative must be to use JDOM in an Applet.


At 10:30 AM 24/05/2001 -0400, you wrote:
> > I just went through the list archives to see if I could find any support
> > for ID and IDREF.  The last thing that I saw was for beta 2, and it said
> > that there wasn't any support for it at the time.  I don't know if
> > things have changed since then.  Have they?
>That requires parsing of the DTD to figure out which attribute
>is the ID attribute.  Non trivial.
> > Also, I know that Werken and Sons are working on an XPath implmentation,
> > and I'm thinking of trying to learn it to use it.  For those of you that
> > have used it, what did you think?  Do you swear by or at it?
>Yes, we have an implementation thas has been target at JDOM, and
>also a port to DOM4J.
>This week, I'm working on a rewrite, attempting to unify the implementation
>to work across all flavors of DOMs (JDOM, DOM4J, w3c DOM).
>Also, I'm getting away from the antlr.org parser-generator, and using
>a highly optimized hand-written parser, to makes things Go Faster.
>Though, the current werken.xpath certainly is usable in the meantime.
>         -bob
>To control your jdom-interest membership:

More information about the jdom-interest mailing list