[jdom-interest] getChildText() by attribute

Igal Corcos scarface at MAGMA.CA
Wed Jan 30 08:03:39 PST 2002


Hello,

Is there a way to get the value associated with an element based on the
value of one of it's attributes?
If not, has anyone considered adding such a method to the Element class...

i.e. getChildTextByAttribute(String name, String attrName, String attrValue)

This method would return the text value for the child element that has an
attribute called 'attrName' and whose value is equal to 'attrValue'... this
would be helpful in situations like the one below:

<Person>
    <Feature name="HairColor">Brown</Feature>
    <Feature name="EyeColor">Blue</Feature>
    <Feature name="Height">5' 10''</Feature>
       ...
</Person>

We could then simply say:
personElement.getChildTextByAttribute("Feature", "name", "HairColor") to get
"Brown"...

Just a thought.
Thanks.
-Igal Corcos







More information about the jdom-interest mailing list