Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] How to Serialize With Indenting Without Altering Newlines?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: Randall R Schulz <rschulz AT sonic.net>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] How to Serialize With Indenting Without Altering Newlines?
  • Date: Tue, 28 Nov 2006 15:50:51 -0800

On Nov 28, 2006, at 3:38 PM, Randall R Schulz wrote:

Hi,

I'm putting a String that sometimes contains newlines into a Text
element. When I serialize those elements with an indent and a MaxLength
in force, the newlines appear to have been replaced with plain spaces
and the text wraps into a block / blob. Not invoking
Serializer.setMaxLength() doesn't stop this alteration, though of
course now the text just wraps at the terminal boundary when I print it
to a terminal emulator. So apparently using Serializer.setIndent(n)
with n > 0 is what triggers it.

This is not critical, since this output mode (under the control of
a "pretty-print" option) is meant only for human consumption (the
program is actually an importer for an eXist database), but I'd like to
know if I can get the indenting without having text elements altered in
this way. Can I?


Currently, XOM's pretty printing (n > 0) is aggressively not preserving the XML Infoset. From the javadoc for setIndent(n):

* When this variable is set to a value greater than 0,
* the serializer does not preserve white space. Spaces,
* tabs, carriage returns, and line feeds can all be
* interchanged at the serializer's discretion, and additional
* white space may be added before and after tags.
* Carriage returns, line feeds, and tabs will not be
* escaped with numeric character references.

However, the doc goes on to mention that xml:space="preserve" can be used to selectively work around it:

* Inside elements with an <code>xml:space="preserve"</code>
* attribute, white space is preserved and no indenting
* takes place, regardless of the setting of the indent
* property, unless, of course, an
* <code>xml:space="default"</code> attribute overrides the
* <code>xml:space="preserve"</code> attribute.

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page