[jdom-interest] setText() to replace children?

dfeather at oreillyauto.com dfeather at oreillyauto.com
Tue Jul 10 10:55:17 PDT 2001

>At 8:50 AM -0700 7/10/01, Alex Chaffee wrote:
>>In fact, it opens the door to a new set of polymorphic methods, just 
like with addContent:
>>  Element setContent(Comment comment)
>>  Element setContent(Element element)
>>  Element setContent(EntityRef entity)
>>  Element setContent(ProcessingInstruction pi)
>>  Element setContent(String text)
>>to go with
>> Element setContent(List content)
>These aren't wrong, but I don't see a lot of need for them. How often do 
you need to set the >content of an element to a processing instruction 
anyway? I'd prefer not to clutter the API and >just have the two 
setContent methods, one for lists and one for strings. 
>| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
>|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
>|              http://www.ibiblio.org/xml/books/bible2/              |
>|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
>|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      | 
>|  Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/     |

I think the setContent(XXX xxx) methods make alot of sense. I think it 
would be a mistake, and kind of annoying to have just setContent methods 
for a List and a String. If you want to take a minimalist approach to the 
question, then why have one specifically for just String? A String is just 
another object, so we might as well do it all with just the List method 
and add the String to the List then add the List.

In my opinion, the many setContent methods would make the API much easier 
to use. If I want to add an Element, I don't need to know that I have to 
add it to a List and then setContent, I can just setContent. The same 
would go for String and everything else, all with one polymorphic method. 
Very convenient if you ask me. I think that this change would facilitate 
removal of some other methods (been a while since I have looked at the 
API) and thus make the API less cluttered. I could be wrong, just my 1.5 

Dan Feather
O'Reilly Automotive, Inc.
417-862-2674 x8949
dfeather at oreillyauto.com

More information about the jdom-interest mailing list