[jdom-interest] Unexpected results with getAttribute & getAttributeValue.
Nick Fankhauser
nickf at ontko.com
Mon Oct 1 10:25:13 PDT 2001
Hi-
I'm running into a problem which may be due to my misunderstanding, or might
be a bug.
I have two elements storing phone information that look identical except
that one has an attribute "FaxID" and the other has attribute "PhoneID".
I'm reading these elements & then storing them in a database that uses the
same table for both, with a column to distinguish fax or phone.
Since they're going into the same table, I'm attempting to use a single
insert routine that sets the Voice/Fax flag based on the existence of the
attributes.
My first idea was to test the return value of getAttribute(String name) to
see if it was null, but I always got a non-null return value, even if the
attribute did not exist. When I looked more closely at the JavaDoc, I saw
that there was no explicit assertion that null was returned if the attribute
didn't exist.
So... I went to plan "B": The JavaDoc for getAttributeValue(String name)
specifically says that it returns a String containing the value or null if
no such attribute.
The problem is that I'm getting back a String containing the word "null" if
the attribute doesn't exist instead of getting a null, so my test is always
true. I think this might be a bug in the JDOM code.
I looked at the B7 source for this & it looks OK (and understandable <grin>)
to me in the Element.getAttributeValue and Attribute.getValue methods. I
learned from this that Element.getAttribute should be returning a null as
well, but I got a bit lost in the constructor for Attribute. I can't discern
how Attribute.value gets set.
Any thoughts? Is this really a bug or a problem on my end?
Thanks!
-Nick
---------------------------------------------------------------------
Nick Fankhauser
More information about the jdom-interest
mailing list