[jdom-interest] Recursively Modifying the JDOM before output.

Gary Montgomery Gary.Montgomery at G11N.COM
Fri Jun 1 14:10:10 PDT 2001


> Gary Montgomery wrote:
> > 
> > So we save <kid/> off to the side with getChildren(). 
> > setText("foo") changes the tree to:
> > 
> > <root>
> > foo
> > </root>
> > 
> > then after addChildren():
> > 
> > <root>
> > foo
> > <kid/>
> > </root>
> 
> That's one workaround.  I'd like to have something better.
> 
> We could also just put the text before or after the other 
> content?  That
> might be less ugly.  Perhaps we could be fancy (too fancy?) and set it
> at the first non-whitespace text node.  As a newbie, what would you
> expect?

Since there are seperate set/getters for text and children nodes, I
envisioned the modification
of text and children to be independant of each other. But I didn't consider
the case of text and nodes
being intermingled as in your example. Actually, I don't tend to mix the two
so I would have written your
example like:

<root>
   <freetext>Here is some text</freetext>
   <kid/>
   <freetext>Here is more text</freetext>
</root>


Which just made me realize that I'm seting text on nodes that should only
contain nodes. But I wanted to get
it working first, then clean things up. Back to your question though, I
guess I'd expect there to be a convention
for the text to be inserted either before all the child nodes or after them
all. If someone doesn't like that then
they can wrap free text such that nodes contain either text or child nodes
but not both. Regardless, the javadocs
should mention that setting text on a node of mixed content will cause the
children to be lost.

Gary






> -jh-
> 



More information about the jdom-interest mailing list