This page is no longer maintained — Please continue to the home page at

My proposed fix for Scala bug #1118 (serialization of empty elements)

No replies
Alex Cruise
Joined: 2008-12-17,
User offline. Last seen 2 years 26 weeks ago.

Hey folks,

Here's the latest version of my proposed fix for #1118. I'd really like
to get some review before I commit it. Lift is CC'd as you guys are
most likely to be impacted by this change if it goes in, and scala-user
because I crave attention. ;)

Here's the patch:

To sum up, the following changes are made:

* Elements that were originally parsed as minimized (i.e. rather
than ) will be serialized in their original form. Currently
is serialized to . I think we can all agree that this
is, uh... wicked suboptimal. ;)

* Elem gets a new constructor and factory method that allow the
minimization behaviour to be chosen explicitly for any Elem that's built
programatically: pass minimizeEmpty = true to indicate that you'd like
this Elem to be serialized in minimized form if empty, and false otherwise.

* Utility.toXML is deprecated because of its all-or-nothing approach to
minimizeTags. Unfortunately I couldn't just add an overload because
overloading is incompatible with named and default arguments. It calls
through to a new method Utility.serialize, which is otherwise identical
except that rather than a Boolean, its minimizeTags parameter must be
one of the following enum values:

** MinimizeMode.Always => Always write empty elements in minimized form
(what you'd get if you passed minimizeTags = true to toXML)

** MinimizeMode.Never => Never write empty elements in minimized form
(what you'd get if you passed minimizeTags = false to toXML)

** MinimizeModel.Default => Write empty elements in minimized form each
according to its minimizeEmpty property, which is set either during
parsing or when Elems are constructed programmatically.

I look forward to your input. Thanks!


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland