[jdom-interest] retrieving an element based on an attribute

Collin Peters collinp at telus.net
Mon Mar 4 20:43:37 PST 2002

Newbie question:

Is there any way to retrieve an element based on an attribute beside looping
though the possible elements and looking for the attribute?

For example, in the following text from the javaworld.com documentation:

<fibonacci index="8">21</fibonacci>
<fibonacci index="9">34</fibonacci>
<fibonacci index="10">55</fibonacci>
<fibonacci index="11">89</fibonacci>
<fibonacci index="12">144</fibonacci>
<fibonacci index="13">233</fibonacci>
<fibonacci index="14">377</fibonacci>
<fibonacci index="15">610</fibonacci>
<fibonacci index="16">987</fibonacci>
<fibonacci index="17">1597</fibonacci>

Is there a one line piece of code to get the fibonacci number at index 12?
The only other way I see to do it is to get the children where the element
name is fibonacci and then loop through looking for the attribute where

Collin Peters

More information about the jdom-interest mailing list