[jdom-interest] Obtaining an Eelement via attribute ID through JDOM?

Liam P. Walker liamw at home.com
Mon Sep 25 21:08:47 PDT 2000


Some background:
================
I have an xml document and a DTD that defines the structure of that
document. 

I have an element with child element that is referred to in my xml using
an attribute of type ID (i.e. I'm referring to an existing element
within my document and only specifying the ID of that element).

e.g. 
<!-- Assume this is valid as I just typed it in and is not my real xml
I'm using.
-->

<elementA>
   <!-- the below element is the element I'm concerned with -->
   <elementB _idref="uniqueId"/> 
</elementA>

<!-- and here it is defined later in my xml 
   attribute _id has an attribute-type of ID
-->
<elementB _id="uniqueId"
   someAttributeA="a"
   someAttributeB="b">
   <subElementA/>
   <subElementB/>
   ...
</elementB>


The problem:
============
When you get the element elementB from its parent element elementA, you
cannot get at elementB's various attributes via getAttribute() and child
elements via getChild() (except the attribute named _idref defined as
attribute type IDREF).  i.e. Although you have an Element object, it
does not contain all the information which was defined for that element
elsewhere in my xml document.  (its not a reference or even a copy of
elementB)

I was hoping that the child element of elementA would be a reference to
the Element object elementB.  Doesn't this make sense - the xml refers
to the same data after all?

Assuming that I am correct is their a handy method that allows me to get
an Element from an xml document via its attribute of type ID so that I
can easily get what I want from this element?  I suppose I could create
this mechanism by figuring out which parser listener I need add myself
to and build a suitable index... 

I'd certainly rather a reference at this point unless someone can give
me a good reason to the contrary.


Thanks,
.maiL

*braces for impact*



More information about the jdom-interest mailing list