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

Steven D. Keens skeens at planetfred.com
Tue Jul 10 09:56:28 PDT 2001


I like your idea but wouldn't it be better if the exception is thrown when
there is mixed content.  Also, getText() could react the same way, by
throwing an exception if it contains mixed content.  Thus, we retain the
convenience of the two methods (isn't that why they exist, for convenience).
Plus we have a consistent and symetric API that behaves predictably.

--
Steven Keens                mailto:skeens at planetfred.com
Planetfred Inc.             http://www.planetfred.com
44 Byward Market, Suite 240, Ottawa, ON, K1N 7A2, Canada

The most exciting phrase in science, the one which heralds
new discoveries, is not "Eureka!", but "That's funny!"
                       -- Issac Asimov


>-----Original Message-----
>From: jdom-interest-admin at jdom.org
>[mailto:jdom-interest-admin at jdom.org]On Behalf Of Richard Cook
>Sent: Tuesday, July 10, 2001 11:38
>To: 'JDOM Interest List'
>Subject: RE: [jdom-interest] setText() to replace children?
>
>
>Could it be a precondition that there is no element content, perhaps an
>exception if there is; setText() is very convenient for data oriented xml,
>but for mixed content you are really dealing with a list of text
>(and other)
>nodes, and setText() seems an invalid operation (a bit like writing
>myArrayList="fred" in java and expecting the first item to become
>"fred" and
>the rest of the list to be obliterated). even getText() on something like
><txt>The <b>cat</b> sat on the <b> mat</b></txt> returns a
>surprising result
>for someone who is scanning the text rather than thinking of structure.
>removeContent could always be used if obliteration is the intent. The
>problem is that behaviour of setText() is then different depending on the
>xml source and may make app testing harder.
>
>-----Original Message-----
>From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
>Behalf Of Alex Rosen
>Sent: 10 July 2001 15:49
>To: 'Elliotte Rusty Harold'; 'JDOM Interest List'
>Subject: RE: [jdom-interest] setText() to replace children?
>
>The only problem with all these proposals is the lack of symmetry. If you
>get
>text by calling getText(), it's natural to set it via setText(), and if
>that's
>not the name of the method, you have to go looking for it, and
>figure out if
>it
>really does what you want it to do. Similarly for setContent() and
>setChildren(). Whether that's a good enough reason to keep the
>current state
>of
>things, I don't know. I really like the intuitiveness of setText(), though.
>In
>the common case where you don't have mixed content, it feels a lot more
>natural.
>
>Alex
>
>_______________________________________________
>To control your jdom-interest membership:
>http://lists.denveronline.net/mailman/options/jdom-interest/youradd
r at yourhos
t.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list