[jdom-interest] ID and IDREF

Murray Altheim Murray.Altheim at eng.sun.com
Tue Sep 5 17:11:42 PDT 2000


Brett McLaughlin wrote:
> 
> veerpal singh wrote:
> >
> > Hi All
> >
> > I was just looking around on net for ID and IDREF processing. Is it 
> possible thru jdom that when idref is encountered, element having iD 
> can be retrieved. Or has to be done by higher level appl.
> 
> What do you need to be able to do, and what would you expect the API to
> look like? Finally, what's your use-case for these changes.
> 
> Let us know, and I'll look at what it would take to do.

I can't speak for Mr. Singh, but IDREF-ID processing is pretty common 
in some places, particularly intra-document links. As a use case example,
simple IDREF linking mechanism might look like:

    <!DOCTYPE book SYSTEM "book.dtd" [
    <!ELEMENT alink  EMPTY >
    <!ATTLIST alink 
        ref    IDREF    #REQUIRED
    >
    ]]>
    <book>
    <toc>
      <tocitem><alink ref="ss1">Section 1</alink>
      <tocitem><alink ref="ss2">Section 2</alink>
      <tocitem><alink ref="ss3">Section 3</alink>
    </toc>
    <sect1>
    <sect2 id="ss1"><title>Section 1</title>
    <para>...</para>
    </sect2>
    <sect2 id="ss2"><title>Section 1</title>
    <para>...</para>
    </sect2>
    <sect2 id="ss3"><title>Section 1</title>
    <para>...</para>
    </sect2>
    </sect1>
    </book>

The idea being that one would be able to easily retrieve a reference to
the element containing the ID pointed to by the IDREF, for navigation,
etc.  [It's kinda sad that HTML didn't use this mechanism rather than the
relative reference for internal links. It's a bit easier and would have
encouraged later HTML language designs to use IDs rather than 'name'
attributes (which are not of type ID, sadly), and we'd have avoided 
having both named and ID'd anchor targets.]

I'd encourage simple IDREF-ID links to be included in JDOM, but with a
proviso: if JDOM aims to be an API for well-formed XML, there's no solid
reason to include features that are particular to XML validation. If 
you're not already creating a hashtable of ID values, the overhead in
terms of memory and performance is probably not worth it, especially
on large documents. But if the hashtable is already there, this feature
request is relatively painless.

OTOH, if JDOM aims to provide an API useful for XML validation, it 
needs to provide *all* features that supportr XML 1.0 validation as
defined in the XML 1.0 Recommendation. Both ID validation (ie., validating
that all attribute values declared as type 'ID' are XML Names and are
unique) and IDREF-ID validation (ie., being able to ascertain that there
is an associated ID for all attribute values declared as type 'IDREF'
within the document) are part of XML 1.0 validation and must be included
if JDOM aims to provide a validation API. The ability to dereference the
IDREF value to a specific element would therefore be a byproduct of this
processing.

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