format-pretty-print doesn't work

According to http://java.sun.com/j2se/1.5.0/docs/api/ I should be able to use the followingDOMImplementationLS domImplementationLS = (DOMImplementationLS) doc.getImplementation();

LSSerializer lsSerializer = domImplementationLS.createLSSerializer();

lsSerializer.getDomConfig().setParameter("format-pretty-print","true");

but when I try to run the code under Java 5 or 6 I getorg.w3c.dom.DOMException: FEATURE_NOT_FOUND: The parameter format-pretty-print is not recognized.

at org.apache.xml.serialize.DOMSerializerImpl.setParameter(Unknown Source)

However, according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6439439 this should be fixed now.

What gives? Is there a way to pretty print XML without resorting to Apache's deprecated API?

[845 byte] By [Eric-the-Ka] at [2007-11-27 8:53:19]
# 1

Even more interesting. If I useDOMStringList list = lsSerializer.getDomConfig().getParameterNames();

for (int i = 0; i < list.getLength(); i++)

LOG.info("DOM Configuration Parameter: " + list.item(i));

it prints out "format-pretty-print" as one of the parameter names.

Eric-the-Ka at 2007-7-12 21:10:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
More interesting non-featureslsSerializer.setNewLine("\r\n"); is a no-op, it does not generate a CR-LF, only the LF.Does no-one test this stuff?
Eric-the-Ka at 2007-7-12 21:10:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

OK, I think I've got this figured out now. This is not a Java problem per se, it's an Apache library problem. I finally got this working by using the latest versions of Xerces (2.9.0) and Xalan (2.7.0) and using the serializer.jar from the Xerces package (not from Xalan).

The newline problem seems to have gone away too with the latest versions.

The down side is that the pretty printing is not nearly as good as with the Apache XMLSerializer API (which is deprecated).

Eric-the-Ka at 2007-7-12 21:10:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...