You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Simon Kitching <si...@ecnetwork.co.nz> on 2003/02/27 22:10:29 UTC

xml.serialize.OutputFormat and preserveSpace

Hi,

I am having some problems serializing a DOM in the format I desire using
org.apache.xml.serialize.XMLSerializer (together with OutputFormat).

I generally want to "pretty print" the output, but don't want the
contents of text nodes to be rearranged as the serializer currently
does.

eg 
 <foo>
    <bar>this
is some
text   with   whitespace</bar>
 </foo>

Unfortunately, calling setPreserveSpace(false) on
org.apache.xml.serialize.OutputFormat causes the text content of node
<bar> to be flattened to a single line, then "wrapped" at the whim of
the pretty-printing code. And calling setPreserveSpace(true) basically
disables pretty-printing.

What I would like is for text nodes to be left alone. Text nodes
containing *only* whitespace can be stripped.

Is this possible to achieve?

I see that method setPreserveSpace The default is space stripping and
all elements that do not specify otherwise or use the default value will
not preserve spaces.

The setPreserveSpace javadoc contains the comment:
  "The default is space stripping and all elements that do not specify
otherwise or use the default value will not preserve spaces".
Does anyone know how you "specify otherwise" for a node?

I can use setCDataElements to cause the nodes I know will have
whitespace in them to be output as CDATA, but (a) I then need to specify
the set of nodes in advance, and (b) my client doesn't like this much.

Any info will be much appreciated..

Thanks,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org