[jdom-interest] setText() to replace children?
Richard Cook
rpc at prismtechnologies.com
Wed Jul 11 02:53:14 PDT 2001
That would be OK for me, I only want to use g/setText() on <el>text</el>.
On anything else I would expect to get an error but the javadoc warning is
clear enough and I'd be quite happy for the error to show up in tests rather
than at runtime.
Conventionally I would expect getText() to return what I can set with
setText(). So if getText() returns a concatenation or recursive
concatenation this seems wrong because setText() can't do that. That would
also make setContent(String) surprising. Also the different name makes it a
little easier from jython (not that this is a valid consideration)
I don't think it should be removed completely; it's perfectly valid for many
apps where validation has already precluded mixed content.
The getChildText*() methods are a little ott perhaps.
-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of Steven D. Keens
Sent: 10 July 2001 17:56
To: 'JDOM Interest List'
Subject: RE: [jdom-interest] setText() to replace children?
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
_______________________________________________
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