[jdom-interest] ID/IDREF

bob bob at accurev.com
Mon Sep 25 12:47:00 PDT 2000

Yah, I figured something like that would work.

My only current sticking point is then having to parse
the DTD/schema to get the information as which attributes
are indeed ID attributes.  Any hints? ;) 

I really don't want to write a DTD parser, and XML-schema
is too much in flux for me to bother with at the moment. ;)
Especially since both are theoretically parsed already by
Xerces (or whichever XML parser is in use to generate the
JDOM, if any.)

Anyhow, id() will probably be amongst the last things I
implement.  (I'm working on following[-sibling] and
preceeding[-sibling] axes currently, which will make
it almost completely done.)

As far as duplicates, I don't think it's exceptional if there
isn't uniqueness.  Doesn't The Standard simply say first-one-wins?

btw, Murrary, is your XPath implementation built on JDOM?
Regardless, is it available as source for perusal?


On Mon, 25 Sep 2000, Murray Altheim wrote:

> 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