You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Gervase Markham <GR...@dataconnection.com> on 2000/09/12 14:32:38 UTC
org.apache.xml.serialize.BaseMarkupSerializer comment handling
I've come across an issue in the above class. In the "comment( String text
)" function around line 580, (Xerces-J 1.1.3) there are several things which
seem odd, to different degrees, about the way this class serializes
comments. The following is based on my (limited) understanding of the code
:-)
I am using the XML serializer in indenting mode with a DOM tree that has no
ignorableWhitespace nodes in it. I wish to serialize the tree in this way,
but to preserve spaces inside comments (which seems to me to be a reasonable
thing to want to do.) The default in that function is not to preserve
whitespace, and that is hard-coded (the second "false" in the call to
printText()).
It seems very strange to me that a) the default behaviour of a serializer
should be not to preserve whitespace inside comments, and b) that it is not
possible to change this behaviour.
I can't register a Comment node as "whitespace preserving" because you can
only do that by giving a list of Elements whose text children should have
whitespace preserved.
I can't subclass XMLSerializer and implement a new version of comment()
because XMLSerializer has been declared "final". I could take a copy of all
the code and give it a different class name, but this seems perverse.
Is this a bug, a feature, or am I missing something?
The other odd things is that it doesn't put a \n either before <!-- or after
-->. The first you could argue the toss on, but surely, if you are doing
"pretty serializing", you always want a \n after -->...
Gerv