[jdom-interest] XML type identification

Kevin E. Allen keallen at mail.stic.net
Wed Nov 13 14:49:04 PST 2002


   This is about a half XML and half JDOM question, but here goes.

Schema looks about like this:

<xs:element name="coordParam2D">
   ... snip ...
</xs:element>

<xs:element name="coordParam3D">
   ... snip ...
</xs:element>

<xs:group name="coordVisParams">
  <xs:choice>
    <xs:element ref="coordParam2D" />
    <xs:element ref="coordParam3D" />
  </xs:choice>
</xs:group>

<xs:element name="coordinateGroup">
  <xs:complexType>
    <xs:sequence>
      ... snip ...
      <xs:group    ref="coordVisParams" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

   Now, here's the problem...  I need to be able to extract, for a list,
all of the elements which fit that 'coordVisParams' element.
Unfortunately, as near as I've been able to figure out, by the type any
naming gets to JDOM (or, honestly, anything else for that matter), all I
have is the actual element name - i.e. coordParam2D or coordParam 3D.

   Short of hard-coding specific element indexes based on the schema - and
making the code hideously vulnerable to schema changes - is there any way
to pull this out?

   By the same token, is there any way to find out what the type of an
Element actually is?  If I want to make a dynamic utility which will, for
instance, create a Map with the element names as keys, and
appropriately-typed (Double, Integer, etc) value objects, is there any way
to do it short of trial-and-error parsing?

Thanks,





More information about the jdom-interest mailing list