[jdom-interest] ID/IDREF

Murray Altheim Murray.Altheim at eng.sun.com
Mon Sep 25 12:04:34 PDT 2000


bob wrote:
> 
> On Sun, 24 Sep 2000, Carey Boldenow wrote:
> 
> > Is it possible to select Elements based on their IDs/IDREFs using JDOM?
> 
> This is something at least my XPath implementation *should* do someday.
> 
> I haven't figure out how, and dunno if I'll need support from the
> JDOM library itself.  It requires access to the DTD/schema of the
> document, as without that additional information, IDs do not
> truly exist.
> 
> Thoughts?

You're correct in that without a schema, it's impossible to know which
attributes have been declared as IDs. But assuming that one does have a
schema, what I did in my parser/XPath implementation is simply to keep
a hashtable of all element-attribute pairs that are declared IDs, and
as I encounter them while parsing an instance, I add the new ID to a
second hashtable. I do a preliminary check to see if the ID already 
exists; if so, throw a uniqueness exception. I didn't find this approach
difficult. A lookup in the latter hashtable provides the node of the
element containing the desired ID value.

Murray

...........................................................................
Murray Altheim, SGML/XML Grease Monkey     <mailto:altheim&#64;eng.sun.com>
XML Technology Center
Sun Microsystems, 1601 Willow Rd., MS UMPK17-102, Menlo Park, CA 94025

      In the evening
      The rice leaves in the garden
      Rustle in the autumn wind
      That blows through my reed hut.  -- Minamoto no Tsunenobu



More information about the jdom-interest mailing list