// Please see end - changed from +1 to -1

At 16:13 18/06/2001 +0100, James Elson wrote:
>Thomas Nichols wrote:
>
> > Ah - this is not what I'd been thinking of. So
> > foo.addEntity ("bar"); // returns foo
> > foo.addElement ("bar"); // returns ref to the new bar Element ?? I'd
> > expected it to return foo.
> >
> > If you return foo in all cases, you can chain addAttribute, addElement etc.
> > freely together.
>
>I'd much rather have the newly created Element back. I've already got a 
>reference
>to the foo Element, and don't want to have to search it to get my newly 
>created
>Element.

Good point.


>Personally I don't think
>
>Element foo = foo.addElement("complexType");
>foo.setAttributeValue("mixed", "true");
>foo.setAttributeValue("bar", "bee");
>
>is that bad, and the new ParseText() helper method cleans things up a lot 
>too, if
>you just want clear code.

parseText() is really what I was after, and I'll probably use it 
extensively from now on.
This is a less satisfactory method when some part of the XML is dynamic 
content -  I have to decide whether to build a StringBuffer with the XML I 
want, with appropriate buffer.append(...) calls, or whether to build the 
fragment entirely with addXYZ() or DocumentHelper.createXYZ() calls.

I see two compelling arguments for the "return self" approach":
1. Orthogonality - all addXYZ() methods behave in the same way.
2. Clarity / ease of use - highly subjective, a design issue.

I see one compelling argument for the "return self, except for addElement() 
which returns the new child" approach:
1. If you want the newly added Element you don't have to go and fetch it again.

However, in every circumstance where I want to keep track of the new 
Element I'd just use
Element newEl = new DefaultElement()
or DocumentHelper.createElement(). The issue seems to me only to arise when 
you do *not* want to keep track of all the "intermediate" nodes you're 
creating.


>Why do you need to create DefaultAttribute elements explicitly?

Um - ? Probably because I'm misunderstanding something? Is the preferred 
method to use DocumentHelper.createAttribute()?
I had actually expected to find an Element.addAttribute (String name, 
String value). Is DefaultAttribute the correct class for a bog-standard 
run-of-the-mill attribute?

>   James


<!-- later -->
Ah, just read reply from James S. and changed my mind! Thanks James and James.



Regards,
Thomas.


_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to