[jdom-interest] Important proposal: Element/Document changes
Jason Hunter
jhunter at collab.net
Tue Jul 25 17:23:02 PDT 2000
"David W. Smiley" wrote:
>
> The new naming proposal sounds nice in general but:
>
> I think getAttributeText() should exist instead of getAttributeValue()
> for consistency with Elements, _even_though_ an Attribute is always
> Text.
Only issue there is then Attribute would need a getText() method to be
consistent with this method, and that's just plain wrong. :-)
Attributes don't have text, they have names and values. (I had the same
idea, but shot it down myself with this reasoning.)
> I am one of those in the camp that believe a
> getChildText(name,namespace) method should exist for all the reasons
> that have been discussed by the proponents of this already. It is a
> common case and will make code more concise.
I'm in the same camp. Since many XML documents (like web.xml) use
element children as essentially attributes, this method makes good
sense. It avoids the damn NPE with getChild().getText(). Any other
campers?
> For some applications, order of elements DOES count (as was recently
> pointed out by a list member). Would it be possible to insert the new
> Content being added into the returned List by getChildElements() using
> list.add(idx,newthing) ?
That should work right now, although if there's mixed content we have to
do some guessing about where to put it, since you're using an index for
only part of the actual content.
> Must addContent(xxxx) and removeContent(xxxx) both be overloaded by all
> Node types? Lets just say, for the sake of argument, that there is a
> Node interface that simply flagged Element, Entity, etc. as being a
> Node. (Maybe it should be called Content, anyways...). Then, if you
> wanted to enable the ability to add/remove an element at a certain
> index, you would have addContent(idx,Node) and removeContent(idx,Node).
> All the instanceof's would only be around twice, once for each of
> these. addContent(Node) and removeContent(Node) would immediately call
> their add/Remove(idx,Node) counterparts with a... lets say a
> Integer.MAX_VALUE which signifies that it goes on the end. Would this
> be easier overall? There would be fewer methods, and it wouldn't really
> be a big deal doing the if-else instanceof section twice.
Can't do it even if we wanted to. Strings can't extend Node.
-jh-
More information about the jdom-interest
mailing list